Lucene.Net  3.0.3
Lucene.Net is a port of the Lucene search engine library, written in C# and targeted at .NET runtime users.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties Pages
Public Member Functions | Static Public Attributes | List of all members
Lucene.Net.Search.Sort Class Reference

Encapsulates sort criteria for returned hits. More...

Public Member Functions

 Sort ()
 Sorts by computed relevance. This is the same sort criteria as calling Searcher.Search(Query,int)without a sort criteria, only with slightly more overhead.
 
 Sort (SortField field)
 Sorts by the criteria in the given SortField.
 
 Sort (params SortField[] fields)
 Sorts in succession by the criteria in each SortField.
 
virtual void SetSort (SortField field)
 Sets the sort to the given criteria.
 
virtual void SetSort (params SortField[] fields)
 Sets the sort to the given criteria in succession.
 
virtual SortField[] GetSort ()
 Representation of the sort criteria.
 
override System.String ToString ()
 
override bool Equals (System.Object o)
 Returns true if o is equal to this.
 
override int GetHashCode ()
 Returns a hash code value for this object.
 

Static Public Attributes

static readonly Sort RELEVANCE = new Sort()
 Represents sorting by computed relevance. Using this sort criteria returns the same results as calling Searcher.Search(Query,int)Searcher::search()without a sort criteria, only with slightly more overhead.
 
static readonly Sort INDEXORDER
 Represents sorting by index order.
 

Detailed Description

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", Integer.toString(x), 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: Integers, Longs, Floats, or Strings. Unless SortField objects are specified, the type of value in the field is determined by parsing the first term in the field.

Integer term values should contain only digits and an optional preceding negative sign. Values must be base 10 and in the range Integer.MIN_VALUE and Integer.MAX_VALUE inclusive. Documents which should appear first in the sort should have low value integers, later documents high values (i.e. the documents should be numbered 1..n where 1 is the first and n the last).

Long term values should contain only digits and an optional preceding negative sign. Values must be base 10 and in the range Long.MIN_VALUE and Long.MAX_VALUE inclusive. Documents which should appear first in the sort should have low value integers, later documents high values.

Float term values should conform to values accepted by float.Parse(string) (except that NaN and Infinity are not supported). Documents which should appear first in the sort should have low values, later documents high values.

String term values can contain any valid String, but should not be tokenized. The values are sorted according to their natural order. Note that using this type of term value has higher memory requirements than the other two types.

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 integer or float array of length 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 String fields, the cache is larger: in addition to the above array, the value of every term in the field is kept in memory. If there are many unique terms in the field, this could be quite large.

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

Definition at line 100 of file Sort.cs.

Constructor & Destructor Documentation

Lucene.Net.Search.Sort.Sort ( )

Sorts by computed relevance. This is the same sort criteria as calling Searcher.Search(Query,int)without a sort criteria, only with slightly more overhead.

Definition at line 120 of file Sort.cs.

Lucene.Net.Search.Sort.Sort ( SortField  field)

Sorts by the criteria in the given SortField.

Definition at line 125 of file Sort.cs.

Lucene.Net.Search.Sort.Sort ( params SortField[]  fields)

Sorts in succession by the criteria in each SortField.

Definition at line 131 of file Sort.cs.

Member Function Documentation

override bool Lucene.Net.Search.Sort.Equals ( System.Object  o)

Returns true if o is equal to this.

Definition at line 171 of file Sort.cs.

override int Lucene.Net.Search.Sort.GetHashCode ( )

Returns a hash code value for this object.

Definition at line 202 of file Sort.cs.

virtual SortField [] Lucene.Net.Search.Sort.GetSort ( )
virtual

Representation of the sort criteria.

Returns
Array of SortField objects used in this sort criteria

Definition at line 151 of file Sort.cs.

virtual void Lucene.Net.Search.Sort.SetSort ( SortField  field)
virtual

Sets the sort to the given criteria.

Definition at line 137 of file Sort.cs.

virtual void Lucene.Net.Search.Sort.SetSort ( params SortField[]  fields)
virtual

Sets the sort to the given criteria in succession.

Definition at line 143 of file Sort.cs.

override System.String Lucene.Net.Search.Sort.ToString ( )

Definition at line 156 of file Sort.cs.

Member Data Documentation

readonly Sort Lucene.Net.Search.Sort.INDEXORDER
static

Represents sorting by index order.

Definition at line 111 of file Sort.cs.

readonly Sort Lucene.Net.Search.Sort.RELEVANCE = new Sort()
static

Represents sorting by computed relevance. Using this sort criteria returns the same results as calling Searcher.Search(Query,int)Searcher::search()without a sort criteria, only with slightly more overhead.

Definition at line 108 of file Sort.cs.


The documentation for this class was generated from the following file: