Class Sort
Encapsulates sort criteria for returned hits.
The fields used to determine sort order must be carefully chosen. Documents must contain a single term in such a field, and the value of the term should indicate the document's relative position in a given sort order. The field must be indexed, but should not be tokenized, and does not need to be stored (unless you happen to want it back with the rest of your document data). In other words:
document.Add(new Field("byNumber", x.ToString(CultureInfo.InvariantCulture), Field.Store.NO, Field.Index.NOT_ANALYZED));
Valid Types of Values
There are four possible kinds of term values which may be put into
sorting fields:
1..n
where
1
is the first and n
the last).
NaN
and Infinity
are not supported).
Documents which should appear first in the sort
should have low values, later documents high values.
Object Reuse
One of these objects can be used multiple times and the sort order changed between usages.
This class is thread safe.
Memory Usage
Sorting uses of caches of term values maintained by the
internal HitQueue(s). The cache is static and contains an IndexReader.MaxDoc
for each field
name for which a sort is performed. In other words, the size of the
cache in bytes is:
4 * IndexReader.MaxDoc * (# of different fields actually used to sort)
For
Note that the size of the cache is not affected by how many fields are in the index and might be used to sort - only by the ones actually used to sort a result set.
Created: Feb 12, 2004 10:53:57 AM
@since lucene 1.4
Inheritance
Namespace: Lucene.Net.Search
Assembly: Lucene.Net.dll
Syntax
public class Sort : object
Constructors
| Improve this Doc View SourceSort()
Sorts by computed relevance. This is the same sort criteria as calling Search(Query, Int32) without a sort criteria, only with slightly more overhead.
Declaration
public Sort()
Sort(SortField)
Sorts by the criteria in the given SortField.
Declaration
public Sort(SortField field)
Parameters
Type | Name | Description |
---|---|---|
SortField | field |
Sort(SortField[])
Sorts in succession by the criteria in each SortField.
Declaration
public Sort(params SortField[] fields)
Parameters
Type | Name | Description |
---|---|---|
SortField[] | fields |
Fields
| Improve this Doc View SourceINDEXORDER
Represents sorting by index order.
Declaration
public static readonly Sort INDEXORDER
Field Value
Type | Description |
---|---|
Sort |
RELEVANCE
Represents sorting by computed relevance. Using this sort criteria returns the same results as calling Search(Query, Int32)without a sort criteria, only with slightly more overhead.
Declaration
public static readonly Sort RELEVANCE
Field Value
Type | Description |
---|---|
Sort |
Properties
| Improve this Doc View SourceNeedsScores
Returns true
if the relevance score is needed to sort documents.
Declaration
public virtual bool NeedsScores { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
Methods
| Improve this Doc View SourceEquals(Object)
Returns true
if o
is equal to this.
Declaration
public override bool Equals(object o)
Parameters
Type | Name | Description |
---|---|---|
System.Object | o |
Returns
Type | Description |
---|---|
System.Boolean |
GetHashCode()
Returns a hash code value for this object.
Declaration
public override int GetHashCode()
Returns
Type | Description |
---|---|
System.Int32 |
GetSort()
Representation of the sort criteria.
Declaration
public virtual SortField[] GetSort()
Returns
Type | Description |
---|---|
SortField[] | Array of SortField objects used in this sort criteria |
Rewrite(IndexSearcher)
Rewrites the SortFields in this Sort, returning a new Sort if any of the fields changes during their rewriting.
Declaration
public virtual Sort Rewrite(IndexSearcher searcher)
Parameters
Type | Name | Description |
---|---|---|
IndexSearcher | searcher | IndexSearcher to use in the rewriting |
Returns
Type | Description |
---|---|
Sort |
|
SetSort(SortField)
Sets the sort to the given criteria.
Declaration
public virtual void SetSort(SortField field)
Parameters
Type | Name | Description |
---|---|---|
SortField | field |
SetSort(SortField[])
Sets the sort to the given criteria in succession.
Declaration
public virtual void SetSort(params SortField[] fields)
Parameters
Type | Name | Description |
---|---|---|
SortField[] | fields |
ToString()
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
System.String |