Package org.apache.lucene.search
Class Sort
java.lang.Object
org.apache.lucene.search.Sort
Encapsulates sort criteria for returned hits.
A Sort can be created with an empty constructor, yielding an object that will instruct
searches to return their hits sorted by relevance; or it can be created with one or more SortFields.
- Since:
- lucene 1.4
- See Also:
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanReturns true ifois equal to this.static SortFieldgetPrimarySortField(LeafReader reader) Returns the primary index sort field for the given LeafReader, or null if none is configured.getSort()Representation of the sort criteria.inthashCode()Returns a hash code value for this object.booleanReturns true if the relevance score is needed to sort documents.rewrite(IndexSearcher searcher) Rewrites the SortFields in this Sort, returning a new Sort if any of the fields changes during their rewriting.toString()
-
Field Details
-
RELEVANCE
Represents sorting by computed relevance. Using this sort criteria returns the same results as callingIndexSearcher#search()without a sort criteria, only with slightly more overhead. -
INDEXORDER
Represents sorting by index order.
-
-
Constructor Details
-
Sort
public Sort()Sorts by computed relevance. This is the same sort criteria as callingIndexSearcher#search()without a sort criteria, only with slightly more overhead. -
Sort
Sets the sort to the given criteria in succession: the first SortField is checked first, but if it produces a tie, then the second SortField is used to break the tie, etc. Finally, if there is still a tie after all SortFields are checked, the internal Lucene docid is used to break it.
-
-
Method Details
-
getSort
Representation of the sort criteria.- Returns:
- Array of SortField objects used in this sort criteria
-
rewrite
Rewrites the SortFields in this Sort, returning a new Sort if any of the fields changes during their rewriting.- Parameters:
searcher- IndexSearcher to use in the rewriting- Returns:
thisif the Sort/Fields have not changed, or a new Sort if there is a change- Throws:
IOException- Can be thrown by the rewriting- WARNING: This API is experimental and might change in incompatible ways in the next release.
-
toString
-
equals
Returns true ifois equal to this. -
hashCode
public int hashCode()Returns a hash code value for this object. -
needsScores
public boolean needsScores()Returns true if the relevance score is needed to sort documents. -
getPrimarySortField
Returns the primary index sort field for the given LeafReader, or null if none is configured.If sorting against a field would have no effect then that SortField is skipped over and the next SortField in the list is returned. This can happen for fields with no values in the segment, or fields that have only a single distinct value.
-