I am doing a search operation by using lucene where i was taking my results by using topscorecollector, but i found that it unable to sort my topscorecollector results. I found it quiet odd to sort that. Can we sort the TopscoreCollector results?
My code looks like this
TopScoreDocCollector collector = TopScoreDocCollector.create(100, true);
indexSearch.Search(andSearchQuery, filter, collector);
ScoreDoc[] hits = collector.TopDocs().scoreDocs;
for (int i = 0; i < hits.Length; i++)
{
int docId = hits[i].doc;
float score = hits[i].score;
Lucene.Net.Documents.Document doc = indexSearch.Doc(docId);
document.Add(doc);
}
Can anybody help me?
Also one more doubt
we can sort the search results like this
Hits hits = IndexSearch.search(searchQuery, filter, sort);
But it is showing that Hits become obselete by Lucene 3.0. so i have opted for TopscoreCollector. But now iam very much confused?
If anyother alternate method for Hits, Please pass that to me…
TopScoreDocCollectorwill return results sorted by score. To get results sorted on a field you will need to use a method overload that returnsTopFieldDocs.IE:
IndexSearcher.Search(query, filter, nResults, sort)If you dont want to limit the number of results use a very large value for the
nResultsparameter. If i remember correctly passingInt32.MAX_VALUEwill make Lucene generate an exception when initializing itsPriorityQueuebutInt32.MAX_VALUE-1is fine.