How to sort the result in Lucene.net in C#?
i am adding special enum to lucene for relevant the search. how i can sort the result who have a specific enum value.
suppose i ad开发者_StackOverflow中文版d Poor moderate Best and i need to get best first in result then how i can do this in Lucene.net.
any way to do this in Lucene.net
Lucene does have its own Sort. Look at the Namespace Lucene.Net.Search.Sort
. Below is an example where I am sorting by DateOfMessage.
Lucene.Net.Search.TopDocsCollector collector = Lucene.Net.Search.TopScoreDocCollector.create(InternalMaxSearchResults, false); // default is relevance
var sortBy = new Lucene.Net.Search.Sort(new Lucene.Net.Search.SortField(SearchIndex.IndexFields.DateOfMessage.ToString(), Lucene.Net.Search.SortField.LONG, true));
collector = Lucene.Net.Search.TopFieldCollector.create(
sortBy,
InternalMaxSearchResults, /* max 500 results */
false,
false,
false,
false);
break;
// search with the collector
searcher.Search(queryMain, collector);
You can use "SimpleFacetedSearch" to categorize the results as poor, moderate, best https://cwiki.apache.org/confluence/display/LUCENENET/Simple+Faceted+Search
精彩评论