首页新闻找找看学习计划

lucene .net 做的全文索引 在本地运行的时候是好的,上传以后就报错,好像是权限问题

0
悬赏园豆:30 [待解决问题]

   public void CreateIndex()         {

            //创建索引库目录             string path = Server.MapPath("indexdata");//索引文件储存位置

            FSDirectory directory = FSDirectory.Open(new DirectoryInfo(path), new NativeFSLockFactory());             //IndexReader:对索引库进行读取的类

            bool isExist = IndexReader.IndexExists(directory); //是否存在索引库文件夹以及索引库特征文件             if (isExist)             {                 //如果索引目录被锁定(比如索引过程中程序异常退出或另一进程在操作索引库),则解锁                 //Q:存在问题 如果一个用户正在对索引库写操作 此时是上锁的 而另一个用户过来操作时 将锁解开了 于是产生冲突 --解决方法后续                 if (IndexWriter.IsLocked(directory))                 {                     IndexWriter.Unlock(directory);                 }             }             //创建一个索引,采用StandardAnalyzer对句子进行分词             IndexWriter indexWriter = new IndexWriter(directory, new PanGuAnalyzer(), true, IndexWriter.MaxFieldLength.UNLIMITED);

            SqlConnection conn = new SqlConnection(@"XXXXXXXXXXX");             conn.Open();

            SqlCommand cmd = new SqlCommand("select ID,Title,[Content] from news", conn);             SqlDataReader reader = cmd.ExecuteReader();             //string sql = "select ID,Title,[Content] from news";             //SqlDataReader reader = helper.GetDataReader(sql);             while (reader.Read())             {                 //域的集合:文档,类似于表的行                 Document doc = new Document();                 //要索引的字段                 doc.Add(new Field("Title", reader["Title"].ToString(), Field.Store.YES, Field.Index.ANALYZED));                 doc.Add(new Field("Content", reader["Content"].ToString(), Field.Store.YES, Field.Index.ANALYZED));                 doc.Add(new Field("URL", "/AboutUs/News.aspx?ID=" + reader["ID"].ToString() + "", Field.Store.YES, Field.Index.ANALYZED));                 indexWriter.AddDocument(doc);             }             reader.Close();             SqlCommand cmd1 = new SqlCommand("select ID,Title,[Content] from service", conn);

            SqlDataReader reader1 = cmd1.ExecuteReader();             //string sql1 = "select ID,Title,[Content] from service";             //SqlDataReader reader1 = helper.GetDataReader(sql1);             while (reader1.Read())             {                 //域的集合:文档,类似于表的行                 Document doc = new Document();                 //要索引的字段                 doc.Add(new Field("Title", reader1["Title"].ToString(), Field.Store.YES, Field.Index.ANALYZED));                 doc.Add(new Field("Content", reader1["Content"].ToString(), Field.Store.YES, Field.Index.ANALYZED));                 doc.Add(new Field("URL", "/Service/ServiceContent.aspx?ID=" + reader1["ID"].ToString() + "", Field.Store.YES, Field.Index.ANALYZED));                 indexWriter.AddDocument(doc);             }             reader1.Close();             SqlCommand cmd2 = new SqlCommand("select ID,Title,[Content] from shops", conn);             SqlDataReader reader2 = cmd2.ExecuteReader();             //string sql2 = "select ID,Title,[Content] from shops";             //SqlDataReader reader2 = helper.GetDataReader(sql2);             while (reader2.Read())             {                 //域的集合:文档,类似于表的行                 Document doc = new Document();                 //要索引的字段                 doc.Add(new Field("Title", reader2["Title"].ToString(), Field.Store.YES, Field.Index.ANALYZED));                 doc.Add(new Field("Content", reader2["Content"].ToString(), Field.Store.YES, Field.Index.ANALYZED));                 doc.Add(new Field("URL", "/Shop.aspx?ID=" + reader2["ID"].ToString() + "", Field.Store.YES, Field.Index.ANALYZED));                 indexWriter.AddDocument(doc);             }             reader2.Close();

            SqlCommand cmd3 = new SqlCommand("select ID,Position,[Describe] from Recruit", conn);             SqlDataReader reader3 = cmd3.ExecuteReader();             //string sql3 = "select ID,Position,[Describe] from Recruit";             //SqlDataReader reader3 = helper.GetDataReader(sql3);             while (reader3.Read())             {                 //域的集合:文档,类似于表的行                 Document doc = new Document();                 //要索引的字段                 doc.Add(new Field("Title", reader3["Position"].ToString(), Field.Store.YES, Field.Index.ANALYZED));                 doc.Add(new Field("Content", reader3["Describe"].ToString(), Field.Store.YES, Field.Index.ANALYZED));                 doc.Add(new Field("URL", "/Recruit.aspx", Field.Store.YES, Field.Index.ANALYZED));                 indexWriter.AddDocument(doc);             }             reader3.Close();             //对索引文件进行优化             indexWriter.Optimize();             indexWriter.Close();

        }

 

 

    }

渣渣程序员的主页 渣渣程序员 | 初学一级 | 园豆:172
提问于:2013-09-11 14:10
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册