The Sort class is a JavaBean that abstractly represents the data needed to calculate a sort on some data set. A sort consists of some {@link String} expression and a {@link SortDirection}. The mechanism for performing the sort is not provided here.
A Sort object can be used by some sorting infrastructure to either parameterise a SQL or XQuery query or to simply sort in-memory Java objects. For example, when converting a Sort into a SQL fragment, a Sort with sortExpression "foo" and sortDirection {@link SortDirection#DESCENDING} couldbe converted into:
ORDER BY FOO DESC
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));
There are four possible kinds of term values which may be put into sorting fields: Integers, Longs, Floats, or Strings. Unless {@link SortField SortField} objects are specified, the type of valuein 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 {@link Float Float.valueOf(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 {@link Comparable natural order}. Note that using this type of term value has higher memory requirements than the other two types.
One of these objects can be used multiple times and the sort order changed between usages.
This class is thread safe.
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 @since lucene 1.4
Sort specification elements are all optional. You could simply say:
List
Sort specification elements are also can appear in any order -- the client implementation will send them to the server in the order expected by the protocol, although it is good form to specify the predicates in natural order:
@author Joubin Houshyar (alphazero@sensesay.net)
@version alpha.0, 04/02/09
@since alpha.0
List
cf:sort
element refers to the default sort order.cf:sort
element refers. If it is omitted, the client should use the value of the "element" attribute as the human-readable name. The "label" attribute is required if the "element" attribute is omitted. cf:sort
element refers.. It contains one of the following values: date, number, text. If it is omitted, the default value is text.cf:sort
element refers is the default sort order in the list. The allowed values are "true" and "false". If omitted, the default value is "false". The items in the list must be already be sorted by the element – this is, the client should not expect to have to resort by this field if it displaying content directly from the list. The client should respect only the first instance of default="true" that it encounters.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|