Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hits Object Deprecated in Lucene.Net 3.03, how do i replace it?

I am working my way through lucene and been stumped on this issue with the Hits object. I have a Using Lucene.Net.Search but for some reason the VS12 Express cannot find the Hits object so the following fails to compile.

The compiler complains about this line

Hits hits = searcher.Search(booleanQuery, hits_limit);

with the following error message

Error 1 The type or namespace name 'Hits' could not be found (are you missing a using directive or an assembly reference?)

I do not get it, according to the online tutorials alk you need is Lucnen.Net.Search

Any Advice

// 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;
like image 477
TheCodeNovice Avatar asked Feb 19 '13 19:02

TheCodeNovice


1 Answers

I use Lucene.net 3.0.3, and Search() returns a TopDocs object, which contains a few properties and an array of ScoreDoc elements. Here is an exemple :

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");
}
like image 50
mbarthelemy Avatar answered Sep 29 '22 20:09

mbarthelemy