为了账号安全,请及时绑定邮箱和手机立即绑定

lucene.net 查询的问题

lucene.net 查询的问题

www说 2018-12-07 10:54:48
最近在学习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  
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 306 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信