-
-
Notifications
You must be signed in to change notification settings - Fork 131
Sorting results
Shannon Deminick edited this page Aug 10, 2016
·
4 revisions
When performing searches with Examine you can also have Examine order the results on a particular field. When the sorting is done by Examine (i.e. Lucene) the processing will be much more efficient than sorting the results after the search results are returned. Further more by having the sorting performed by Lucene, effective paging can be achieved.
By default, the results are sorted by Score which is generally what you'd want. However in some cases you might want to sort on a custom field. This is easily done by using the OrderBy or OrderByDescending methods on the ISearchCriteria instance. For example:
ISearchCriteria sc = ExamineManager.Instance.CreateSearchCriteria(
IndexType.Content /* type of index to query */);
IBooleanOperation query = sc.NodeName("Examine").And().Range("createdDate",
new DateTime(2010, 03, 21),
// will match all nodes which have the name Examine created between the 21st and the 31st March 2010).
new DateTime(2010, 03, 31);
IEnumerable<SearchResult> results = ExamineManager.Instance.Search(
query.Compile(), /* prepares the query to be handled by the searcher /*
100 /* optional max record count */);