我正在通过lucene工作,并在Hits对象上遇到了这个问题.我有一个使用Lucene.Net.Search但由于某种原因,VS12 Express无法找到Hits对象,因此以下无法编译.
编译器抱怨这一行
Hits hits = searcher.Search(booleanQuery,hits_limit);
以下错误消息
Error 1 The type or namespace name ‘Hits’ could not be found (are you
missing a using directive or an assembly reference?)
我不明白,根据你需要的在线教程,是Lucnen.Net.Search
任何建议
// validation if (subqueries.Count == 0) return new List<MATS_Doc>(); // set up lucene searcher Searcher searcher = new IndexSearcher(_directory,false); var hits_limit = 1000; var analyzer = new StandardAnalyzer(Version.LUCENE_30); BooleanQuery booleanQuery = new BooleanQuery(); foreach (Query fieldQuery in subqueries) { booleanQuery.Add(fieldQuery,Occur.SHOULD); } //var parser = new QueryParser(Version.LUCENE_30,searchField,analyzer); //var query = _parseQuery(searchQuery,parser); Hits hits = searcher.Search(booleanQuery,hits_limit); IEnumerable<MATS_Doc> results = _mapLuceneSearchResultsToDataList(hits,searcher); analyzer.Close(); searcher.Dispose(); return results;
解决方法
我使用Lucene.net 3.0.3,而Search()返回一个TopDocs对象,该对象包含一些属性和一个scoreDoc元素数组.这是一个例子:
Lucene.Net.Search.TopDocs results = searcher.Search(booleanQuery,null,hits_limit); foreach(scoreDoc scoreDoc in results.scoreDocs){ // retrieve the document from the 'scoreDoc' object Lucene.Net.Documents.Document doc = searcher.Doc(scoreDoc.Doc); string myFieldValue = doc.get("myField"); }