首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

lucene.net的搜索有关问题,多谢指点

2012-05-30 
lucene.net的搜索问题,谢谢指点。我最近在研究用Lucene做网站搜索功能,遇到如下问题,代码如下创建索引priva

lucene.net的搜索问题,谢谢指点。
我最近在研究用Lucene做网站搜索功能,遇到如下问题,代码如下

创建索引 

private static void CreateIndex()
  {
  string path = @"d:\search\";
  IndexWriter writer = new IndexWriter(path, new StandardAnalyzer(),true);
  Document doc = new Document();
  string strSQL = "SELECT TOP 100 title FROM Article ";
  DataTable dt = SqlHelper.ExecuteDataTable(strSQL);
  foreach (DataRow dr in dt.Rows)
  {
  doc.Add(new Field("title", dr["title"].ToString(), Field.Store.YES, Field.Index.TOKENIZED));
  writer.AddDocument(doc);
  }
   
  writer.Optimize();
  writer.Close();
  }

搜索
private static void Search(string words)
  { 
  string path = @"d:\search\";
  IndexSearcher searcher = new IndexSearcher(path);
  Query query = new QueryParser("title", new StandardAnalyzer()).Parse(words);
  Hits hits = searcher.Search(query);
  Console.WriteLine(hits.Length());
  for (int i = 0; i < hits.Length(); i++)
  {
  Document doc = hits.Doc(i);
  string title = doc.Get("title").ToString();
  Console.WriteLine(title);
  }
  searcher.Close();
  }

现在的问题是,我无论输入的什么关键词,都返回上面SQL查询的第一列的title
请问是哪里写错了,请指教。

[解决办法]
好久不弄了,帮你UP下

热点排行