Lucene++ - a full-featured, c++ search engine
API Documentation

- Main Page
- Related Pages
- Namespaces
- Data Structures
- Files

- Data Structures
- Class Hierarchy
- Data Fields

All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Public Member Functions | Static Public Member Functions | Data Fields
Lucene::Sort Class Reference

Encapsulates sort criteria for returned hits. More...

`#include <Sort.h>`

Inheritance diagram for Lucene::Sort:

## Public Member Functions

| Sort ()
| Sorts by computed relevance. This is the same sort criteria as calling Searcher#search() without a sort criteria, only with slightly more overhead. More...
| Sort (SortFieldPtr field)
| Sorts by the criteria in the given SortField. More...
| Sort (Collection< SortFieldPtr > fields)
| Sorts in succession by the criteria in each SortField. More...
virtual | ~Sort ()
virtual String | getClassName ()
boost::shared_ptr< Sort > | shared_from_this ()
void | setSort (SortFieldPtr field)
| Sets the sort to the given criteria. More...
void | setSort (Collection< SortFieldPtr > fields)
| Sets the sort to the given criteria in succession. More...
Collection< SortFieldPtr > | getSort ()
| Representation of the sort criteria. More...
virtual String | toString ()
| Returns a string representation of the object. More...
virtual bool | equals (LuceneObjectPtr other)
| Return whether two objects are equal. More...
virtual int32_t | hashCode ()
| Return hash code for this object. More...
Public Member Functions inherited from Lucene::LuceneObject
virtual | ~LuceneObject ()
virtual void | initialize ()
| Called directly after instantiation to create objects that depend on this object being fully constructed. More...
virtual LuceneObjectPtr | clone (LuceneObjectPtr other=LuceneObjectPtr())
| Return clone of this object. More...
virtual int32_t | compareTo (LuceneObjectPtr other)
| Compare two objects. More...
Public Member Functions inherited from Lucene::LuceneSync
virtual | ~LuceneSync ()
virtual SynchronizePtr | getSync ()
| Return this object synchronize lock. More...
virtual LuceneSignalPtr | getSignal ()
| Return this object signal. More...
virtual void | lock (int32_t timeout=0)
| Lock this object using an optional timeout. More...
virtual void | unlock ()
| Unlock this object. More...
virtual bool | holdsLock ()
| Returns true if this object is currently locked by current thread. More...
virtual void | wait (int32_t timeout=0)
| Wait for signal using an optional timeout. More...
virtual void | notifyAll ()
| Notify all threads waiting for signal. More...

## Static Public Member Functions

static String | _getClassName ()
static SortPtr | RELEVANCE ()
| Represents sorting by computed relevance. Using this sort criteria returns the same results as calling Searcher#search() without a sort criteria, only with slightly more overhead. More...
static SortPtr | INDEXORDER ()
| Represents sorting by index order. More...

## Data Fields

Collection< SortFieldPtr > | fields
| Internal representation of the sort criteria. More...

## Additional Inherited Members

Protected Member Functions inherited from Lucene::LuceneObject
| LuceneObject ()
Protected Attributes inherited from Lucene::LuceneSync
SynchronizePtr | objectLock
LuceneSignalPtr | objectSignal

## 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(newLucene<Field>(L"byNumber", StringUtils::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, Doubles, 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 INT_MIN and INT_MAX inclusive. Documents which should appear first in the sort should have low value integers, later documents high values (ie. 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 LLONG_MIN and LLONG_MAX inclusive. Documents which should appear first in the sort should have low value integers, later documents high values.

Double term values should conform to values accepted by Double (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 comparable 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 double 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.

## Constructor & Destructor Documentation

Lucene::Sort::Sort | ( | ) |  |

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

Lucene::Sort::Sort | ( | SortFieldPtr | field) |  |

Sorts by the criteria in the given SortField.

Lucene::Sort::Sort | ( | Collection< SortFieldPtr > | fields) |  |

Sorts in succession by the criteria in each SortField.

virtual Lucene::Sort::~Sort | ( | ) |  |

virtual

## Member Function Documentation

static String Lucene::Sort::_getClassName | ( | ) |  |

inline static

virtual bool Lucene::Sort::equals | ( | LuceneObjectPtr | other) |  |

virtual

Return whether two objects are equal.

Reimplemented from Lucene::LuceneObject.

virtual String Lucene::Sort::getClassName | ( | ) |  |

inline virtual

Collection<SortFieldPtr> Lucene::Sort::getSort | ( | ) |  |

Representation of the sort criteria.

Returns
  Array of SortField objects used in this sort criteria

virtual int32_t Lucene::Sort::hashCode | ( | ) |  |

virtual

Return hash code for this object.

Reimplemented from Lucene::LuceneObject.

static SortPtr Lucene::Sort::INDEXORDER | ( | ) |  |

static

Represents sorting by index order.

static SortPtr Lucene::Sort::RELEVANCE | ( | ) |  |

static

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

void Lucene::Sort::setSort | ( | SortFieldPtr | field) |  |

Sets the sort to the given criteria.

void Lucene::Sort::setSort | ( | Collection< SortFieldPtr > | fields) |  |

Sets the sort to the given criteria in succession.

boost::shared_ptr< Sort > Lucene::Sort::shared_from_this | ( | ) |  |

inline

virtual String Lucene::Sort::toString | ( | ) |  |

virtual

Returns a string representation of the object.

Reimplemented from Lucene::LuceneObject.

## Field Documentation

Collection<SortFieldPtr> Lucene::Sort::fields

Internal representation of the sort criteria.

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

- Sort.h

clucene.sourceforge.net