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

Public Member Functions | Static Public Member Functions
Lucene::FieldComparator Class Referenceabstract

A FieldComparator compares hits so as to determine their sort order when collecting the top results with TopFieldCollector. The concrete public FieldComparator classes here correspond to the SortField types. More...

`#include <FieldComparator.h>`

Inheritance diagram for Lucene::FieldComparator:

## Public Member Functions

virtual | ~FieldComparator ()
virtual String | getClassName ()
boost::shared_ptr< FieldComparator > | shared_from_this ()
virtual int32_t | compare (int32_t slot1, int32_t slot2)=0
| Compare hit at slot1 with hit at slot2. More...
virtual void | setBottom (int32_t slot)=0
| Set the bottom slot, ie the "weakest" (sorted last) entry in the queue. When compareBottom is called, you should compare against this slot. This will always be called before compareBottom. More...
virtual int32_t | compareBottom (int32_t doc)=0
| Compare the bottom of the queue with doc. This will only invoked after setBottom has been called. This should return the same result as compare(int,int)} as if bottom were slot1 and the new document were slot 2. More...
virtual void | copy (int32_t slot, int32_t doc)=0
| This method is called when a new hit is competitive. You should copy any state associated with this document that will be required for future comparisons, into the specified slot. More...
virtual void | setNextReader (const IndexReaderPtr &reader, int32_t docBase)=0
| Set a new Reader. All doc correspond to the current Reader. More...
virtual void | setScorer (const ScorerPtr &scorer)
| Sets the Scorer to use in case a document's score is needed. More...
virtual ComparableValue | value (int32_t slot)=0
| Return the actual value in the slot. 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 (const LuceneObjectPtr &other=LuceneObjectPtr())
| Return clone of this object. More...
virtual int32_t | hashCode ()
| Return hash code for this object. More...
virtual bool | equals (const LuceneObjectPtr &other)
| Return whether two objects are equal. More...
virtual int32_t | compareTo (const LuceneObjectPtr &other)
| Compare two objects. More...
virtual String | toString ()
| Returns a string representation of the object. 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 ()

## Additional Inherited Members

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

## Detailed Description

A FieldComparator compares hits so as to determine their sort order when collecting the top results with TopFieldCollector. The concrete public FieldComparator classes here correspond to the SortField types.

This API is designed to achieve high performance sorting, by exposing a tight interaction with {} as it visits hits. Whenever a hit is competitive, it's enrolled into a virtual slot, which is an int ranging from 0 to numHits-1. The FieldComparator} is made aware of segment transitions during searching in case any internal state it's tracking needs to be recomputed during these transitions. A comparator must define these functions: compare Compare a hit at 'slot a' with hit 'slot b'.

setBottom This method is called by FieldValueHitQueue to notify the FieldComparator of the current weakest ("bottom") slot. Note that this slot may not hold the weakest value according to your comparator, in cases where your comparator is not the primary one (ie, is only used to break ties from the comparators before it).

compareBottom Compare a new hit (docID) against the "weakest" (bottom) entry in the queue.

copy Installs a new hit into the priority queue. The FieldValueHitQueue calls this method when a new hit is competitive.

setNextReader Invoked when the search is switching to the next segment. You may need to update internal state of the comparator, for example retrieving new values from the FieldCache.

value Return the sort value stored in the specified slot. This is only called at the end of the search, in order to populate FieldDoc#fields when returning the top results.

## Constructor & Destructor Documentation

## ◆ ~FieldComparator()

virtual Lucene::FieldComparator::~FieldComparator | ( |  | ) |

virtual

## Member Function Documentation

## ◆ _getClassName()

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

inline static

## ◆ compare()

virtual int32_t Lucene::FieldComparator::compare | ( | int32_t | slot1,
|  | int32_t | slot2
| ) |  |

pure virtual

Compare hit at slot1 with hit at slot2.

Parameters

  slot1 | first slot to compare
  slot2 | second slot to compare

Returns
  any N < 0 if slot2's value is sorted after slot1, any N > 0 if the slot2's value is sorted before slot1 and 0 if they are equal

Implemented in Lucene::StringValComparator, Lucene::StringOrdValComparator, Lucene::StringComparatorLocale, Lucene::RelevanceComparator, Lucene::LongComparator, Lucene::IntComparator, Lucene::DoubleComparator, Lucene::NumericComparator< TYPE >, Lucene::NumericComparator< int64_t >, Lucene::NumericComparator< double >, Lucene::NumericComparator< uint8_t >, and Lucene::NumericComparator< int32_t >.

## ◆ compareBottom()

virtual int32_t Lucene::FieldComparator::compareBottom | ( | int32_t | doc | ) |

pure virtual

Compare the bottom of the queue with doc. This will only invoked after setBottom has been called. This should return the same result as compare(int,int)} as if bottom were slot1 and the new document were slot 2.

For a search that hits many results, this method will be the hotspot (invoked by far the most frequently).

Parameters

  doc | that was hit

Returns
  any N < 0 if the doc's value is sorted after the bottom entry (not competitive), any N > 0 if the doc's value is sorted before the bottom entry and 0 if they are equal.

Implemented in Lucene::StringValComparator, Lucene::StringOrdValComparator, Lucene::StringComparatorLocale, Lucene::RelevanceComparator, Lucene::LongComparator, Lucene::IntComparator, Lucene::DoubleComparator, Lucene::DocComparator, Lucene::NumericComparator< TYPE >, Lucene::NumericComparator< int64_t >, Lucene::NumericComparator< double >, Lucene::NumericComparator< uint8_t >, and Lucene::NumericComparator< int32_t >.

## ◆ copy()

virtual void Lucene::FieldComparator::copy | ( | int32_t | slot,
|  | int32_t | doc
| ) |  |

pure virtual

This method is called when a new hit is competitive. You should copy any state associated with this document that will be required for future comparisons, into the specified slot.

Parameters

  slot | which slot to copy the hit to
  doc | docID relative to current reader

Implemented in Lucene::StringValComparator, Lucene::StringOrdValComparator, Lucene::StringComparatorLocale, Lucene::RelevanceComparator, Lucene::DocComparator, Lucene::NumericComparator< TYPE >, Lucene::NumericComparator< int64_t >, Lucene::NumericComparator< double >, Lucene::NumericComparator< uint8_t >, and Lucene::NumericComparator< int32_t >.

## ◆ getClassName()

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

inline virtual

Reimplemented in Lucene::StringValComparator, Lucene::StringOrdValComparator, Lucene::StringComparatorLocale, Lucene::RelevanceComparator, Lucene::LongComparator, Lucene::IntComparator, Lucene::DoubleComparator, Lucene::DocComparator, and Lucene::ByteComparator.

## ◆ setBottom()

virtual void Lucene::FieldComparator::setBottom | ( | int32_t | slot | ) |

pure virtual

Set the bottom slot, ie the "weakest" (sorted last) entry in the queue. When compareBottom is called, you should compare against this slot. This will always be called before compareBottom.

Parameters

  slot | the currently weakest (sorted last) slot in the queue

Implemented in Lucene::StringValComparator, Lucene::StringOrdValComparator, Lucene::StringComparatorLocale, Lucene::NumericComparator< TYPE >, Lucene::NumericComparator< int64_t >, Lucene::NumericComparator< double >, Lucene::NumericComparator< uint8_t >, and Lucene::NumericComparator< int32_t >.

## ◆ setNextReader()

virtual void Lucene::FieldComparator::setNextReader | ( | const IndexReaderPtr & | reader,
|  | int32_t | docBase
| ) |  |

pure virtual

Set a new Reader. All doc correspond to the current Reader.

Parameters

  reader | current reader
  docBase | docBase of this reader

Implemented in Lucene::StringValComparator, Lucene::StringOrdValComparator, Lucene::StringComparatorLocale, Lucene::RelevanceComparator, Lucene::LongComparator, Lucene::IntComparator, Lucene::DoubleComparator, Lucene::DocComparator, and Lucene::ByteComparator.

## ◆ setScorer()

virtual void Lucene::FieldComparator::setScorer | ( | const ScorerPtr & | scorer | ) |

virtual

Sets the Scorer to use in case a document's score is needed.

Parameters

  scorer | Scorer instance that you should use to obtain the current hit's score, if necessary.

Reimplemented in Lucene::RelevanceComparator.

## ◆ shared_from_this()

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

inline

## ◆ value()

virtual ComparableValue Lucene::FieldComparator::value | ( | int32_t | slot | ) |

pure virtual

Return the actual value in the slot.

Parameters

  slot | the value

Returns
  value in this slot upgraded to ComparableValue

Implemented in Lucene::StringValComparator, Lucene::StringOrdValComparator, Lucene::StringComparatorLocale, Lucene::NumericComparator< TYPE >, Lucene::NumericComparator< int64_t >, Lucene::NumericComparator< double >, Lucene::NumericComparator< uint8_t >, and Lucene::NumericComparator< int32_t >.

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

- FieldComparator.h

clucene.sourceforge.net