lucene.net 查询的问题

最近在学习lucene.net,跟着网上的例子学着做了一个例子,但是不知道为什么搜索索引的时候hits.length总是0,请帮忙看一下,谢谢

#region 索引条件
public ActionResult ResumeIndexSearch()
{
List
<string> list = new List<string>() {"北京","三年","java"};
for (int i = 0; i < list.Count; i++)
{
IndexSearch(list[i]);
}
return View("ResumeQuickSearch");
}
#endregion

 

#region 搜索索引
public void IndexSearch(String queryString)
{
EntityList list
= new EntityList();
Hits hits
= null;
try
{
IndexSearcher searcher
= new IndexSearcher("d:/index");
queryString
= GetKeyWordsSplitBySpace(queryString, new KTDictSegTokenizer());

QueryParser contentParser
= new QueryParser("content", new KTDictSegAnalyzer());
Query contentQuery
= contentParser.Parse(queryString);

QueryParser cityParser
= new QueryParser("city", new KTDictSegAnalyzer());
Query cityQuery
= contentParser.Parse(queryString);

QueryParser skillParser
= new QueryParser("skill", new KTDictSegAnalyzer());
Query skillQuery
= contentParser.Parse(queryString);

BooleanQuery bquery
= new BooleanQuery();
bquery.Add(contentQuery, BooleanClause.Occur.MUST);
bquery.Add(cityQuery, BooleanClause.Occur.MUST);
bquery.Add(skillQuery, BooleanClause.Occur.MUST);

hits
= searcher.Search(bquery);

System.Web.HttpContext.Current.Response.Write(
"------------hits:" + hits.Length() + "\r\n\\");

ArrayList entities
= new ArrayList();
for (int i = 0; i < hits.Length(); i++)
{
Document doc
= hits.Doc(i);
LuceneEntity entity
= new LuceneEntity();
entity.Id
= doc.Get("id");
entity.Title
= doc.Get("name");
entity.Type
= doc.Get("type");
entity.URL
= doc.Get("url");
entity.Content
= doc.Get("content");
entity.CreateDate
= doc.Get("time");
entities.Add(entity);
System.Web.HttpContext.Current.Response.Write(
"------------content id:" + doc.Get("id") + "\r\n\\");
}
list.Count
= hits.Length();
list.List
= entities;
searcher.Close();
}
catch(Exception e)
{
System.Web.HttpContext.Current.Response.Write(
"----------error:" + e.Message + "---" + e.ToString());
}
}
#endregion

 

www说
浏览 307回答 1
1回答
打开App,查看更多内容
随时随地看视频慕课网APP