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


Loading...
Searching...
No Matches
FieldComparator.h
Go to the documentation of this file.
1
2// Copyright (c) 2009-2014 Alan Wright. All rights reserved.
3// Distributable under the terms of either the Apache License (Version 2.0)
4// or the GNU Lesser General Public License.
6
7#ifndef FIELDCOMPARATOR_H
8#define FIELDCOMPARATOR_H
9
10#include "LuceneObject.h"
11
12namespace Lucene {
13
42class LPPAPI FieldComparator : public LuceneObject {
43public:
46
47public:
53 virtual int32_t compare(int32_t slot1, int32_t slot2) = 0;
54
58 virtual void setBottom(int32_t slot) = 0;
59
69 virtual int32_t compareBottom(int32_t doc) = 0;
70
75 virtual void copy(int32_t slot, int32_t doc) = 0;
76
81 virtual void setNextReader(const IndexReaderPtr& reader, int32_t docBase) = 0;
82
85 virtual void setScorer(const ScorerPtr& scorer);
86
90 virtual ComparableValue value(int32_t slot) = 0;
91};
92
93template <typename TYPE>
95public:
96 NumericComparator(int32_t numHits, const String& field = EmptyString) {
98 this->field = field;
99 this->bottom = 0;
100 }
101
103 }
104
105protected:
108 String field;
109 TYPE bottom;
110
111public:
112 virtual int32_t compare(int32_t slot1, int32_t slot2) {
113 return (int32_t)(values[slot1] - values[slot2]);
114 }
115
116 virtual int32_t compareBottom(int32_t doc) {
117 return (int32_t)(bottom - currentReaderValues[doc]);
118 }
119
120 virtual void copy(int32_t slot, int32_t doc) {
121 values[slot] = currentReaderValues[doc];
122 }
123
124 virtual void setBottom(int32_t slot) {
125 bottom = values[slot];
126 }
127
128 virtual ComparableValue value(int32_t slot) {
129 return ComparableValue(values[slot]);
130 }
131};
132
134class LPPAPI ByteComparator : public NumericComparator<uint8_t> {
135public:
136 ByteComparator(int32_t numHits, const String& field, const ParserPtr& parser);
138
140
141protected:
143
144public:
145 virtual void setNextReader(const IndexReaderPtr& reader, int32_t docBase);
146};
147
149class LPPAPI DocComparator : public NumericComparator<int32_t> {
150public:
151 DocComparator(int32_t numHits);
152 virtual ~DocComparator();
153
155
156protected:
157 int32_t docBase;
158
159public:
160 virtual int32_t compareBottom(int32_t doc);
161 virtual void copy(int32_t slot, int32_t doc);
162 virtual void setNextReader(const IndexReaderPtr& reader, int32_t docBase);
163};
164
166class LPPAPI DoubleComparator : public NumericComparator<double> {
167public:
168 DoubleComparator(int32_t numHits, const String& field, const ParserPtr& parser);
170
172
173protected:
175
176public:
177 virtual int32_t compare(int32_t slot1, int32_t slot2);
178 virtual int32_t compareBottom(int32_t doc);
179 virtual void setNextReader(const IndexReaderPtr& reader, int32_t docBase);
180};
181
183class LPPAPI IntComparator : public NumericComparator<int32_t> {
184public:
185 IntComparator(int32_t numHits, const String& field, const ParserPtr& parser);
186 virtual ~IntComparator();
187
189
190protected:
192
193public:
194 virtual int32_t compare(int32_t slot1, int32_t slot2);
195 virtual int32_t compareBottom(int32_t doc);
196 virtual void setNextReader(const IndexReaderPtr& reader, int32_t docBase);
197};
198
200class LPPAPI LongComparator : public NumericComparator<int64_t> {
201public:
202 LongComparator(int32_t numHits, const String& field, const ParserPtr& parser);
204
206
207protected:
209
210public:
211 virtual int32_t compare(int32_t slot1, int32_t slot2);
212 virtual int32_t compareBottom(int32_t doc);
213 virtual void setNextReader(const IndexReaderPtr& reader, int32_t docBase);
214};
215
219class LPPAPI RelevanceComparator : public NumericComparator<double> {
220public:
221 RelevanceComparator(int32_t numHits);
223
225
226protected:
228
229public:
230 virtual int32_t compare(int32_t slot1, int32_t slot2);
231 virtual int32_t compareBottom(int32_t doc);
232 virtual void copy(int32_t slot, int32_t doc);
233 virtual void setNextReader(const IndexReaderPtr& reader, int32_t docBase);
234 virtual void setScorer(const ScorerPtr& scorer);
235};
236
239public:
240 StringComparatorLocale(int32_t numHits, const String& field, const std::locale& locale);
242
244
245protected:
248 String field;
250 String bottom;
251
252public:
253 virtual int32_t compare(int32_t slot1, int32_t slot2);
254 virtual int32_t compareBottom(int32_t doc);
255 virtual void copy(int32_t slot, int32_t doc);
256 virtual void setNextReader(const IndexReaderPtr& reader, int32_t docBase);
257 virtual void setBottom(int32_t slot);
258 virtual ComparableValue value(int32_t slot);
259};
260
267public:
268 StringOrdValComparator(int32_t numHits, const String& field, int32_t sortPos, bool reversed);
270
272
273protected:
277
281 String field;
282
283 int32_t bottomSlot;
284 int32_t bottomOrd;
287 int32_t sortPos;
288
289public:
290 virtual int32_t compare(int32_t slot1, int32_t slot2);
291 virtual int32_t compareBottom(int32_t doc);
292 virtual void copy(int32_t slot, int32_t doc);
293 virtual void setNextReader(const IndexReaderPtr& reader, int32_t docBase);
294 virtual void setBottom(int32_t slot);
295 virtual ComparableValue value(int32_t slot);
297 virtual int32_t getBottomSlot();
298 virtual String getField();
299
300protected:
301 void convert(int32_t slot);
302 int32_t binarySearch(Collection<String> lookup, const String& key, int32_t low, int32_t high);
303};
304
308public:
309 StringValComparator(int32_t numHits, const String& field);
311
313
314protected:
317 String field;
318 String bottom;
319
320public:
321 virtual int32_t compare(int32_t slot1, int32_t slot2);
322 virtual int32_t compareBottom(int32_t doc);
323 virtual void copy(int32_t slot, int32_t doc);
324 virtual void setNextReader(const IndexReaderPtr& reader, int32_t docBase);
325 virtual void setBottom(int32_t slot);
326 virtual ComparableValue value(int32_t slot);
327};
328
329}
330
331#endif
#define LUCENE_CLASS(Name)
Definition LuceneObject.h:24
Parses field's values as byte (using FieldCache#getBytes and sorts by ascending value.
Definition FieldComparator.h:134
virtual void setNextReader(const IndexReaderPtr &reader, int32_t docBase)
Set a new Reader. All doc correspond to the current Reader.
ByteComparator(int32_t numHits, const String &field, const ParserPtr &parser)
ByteParserPtr parser
Definition FieldComparator.h:142
Utility template class to handle collections that can be safely copied and shared.
Definition Collection.h:17
static this_type newInstance(int32_t size=0)
Definition Collection.h:33
Sorts by ascending docID.
Definition FieldComparator.h:149
virtual void copy(int32_t slot, int32_t doc)
This method is called when a new hit is competitive. You should copy any state associated with this d...
virtual void setNextReader(const IndexReaderPtr &reader, int32_t docBase)
Set a new Reader. All doc correspond to the current Reader.
int32_t docBase
Definition FieldComparator.h:157
DocComparator(int32_t numHits)
virtual int32_t compareBottom(int32_t doc)
Compare the bottom of the queue with doc. This will only invoked after setBottom has been called....
Parses field's values as double (using FieldCache#getDoubles and sorts by ascending value.
Definition FieldComparator.h:166
DoubleComparator(int32_t numHits, const String &field, const ParserPtr &parser)
virtual int32_t compare(int32_t slot1, int32_t slot2)
Compare hit at slot1 with hit at slot2.
DoubleParserPtr parser
Definition FieldComparator.h:174
virtual int32_t compareBottom(int32_t doc)
Compare the bottom of the queue with doc. This will only invoked after setBottom has been called....
virtual void setNextReader(const IndexReaderPtr &reader, int32_t docBase)
Set a new Reader. All doc correspond to the current Reader.
A FieldComparator compares hits so as to determine their sort order when collecting the top results w...
Definition FieldComparator.h:42
virtual void setScorer(const ScorerPtr &scorer)
Sets the Scorer to use in case a document's score is needed.
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....
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 d...
virtual void setBottom(int32_t slot)=0
Set the bottom slot, ie the "weakest" (sorted last) entry in the queue. When compareBottom is called,...
virtual ComparableValue value(int32_t slot)=0
Return the actual value in the slot.
virtual void setNextReader(const IndexReaderPtr &reader, int32_t docBase)=0
Set a new Reader. All doc correspond to the current Reader.
virtual int32_t compare(int32_t slot1, int32_t slot2)=0
Compare hit at slot1 with hit at slot2.
Parses field's values as int (using FieldCache#getInts and sorts by ascending value.
Definition FieldComparator.h:183
IntParserPtr parser
Definition FieldComparator.h:191
IntComparator(int32_t numHits, const String &field, const ParserPtr &parser)
virtual void setNextReader(const IndexReaderPtr &reader, int32_t docBase)
Set a new Reader. All doc correspond to the current Reader.
virtual int32_t compare(int32_t slot1, int32_t slot2)
Compare hit at slot1 with hit at slot2.
virtual int32_t compareBottom(int32_t doc)
Compare the bottom of the queue with doc. This will only invoked after setBottom has been called....
Parses field's values as long (using FieldCache#getLongs and sorts by ascending value.
Definition FieldComparator.h:200
LongParserPtr parser
Definition FieldComparator.h:208
virtual int32_t compareBottom(int32_t doc)
Compare the bottom of the queue with doc. This will only invoked after setBottom has been called....
virtual int32_t compare(int32_t slot1, int32_t slot2)
Compare hit at slot1 with hit at slot2.
LongComparator(int32_t numHits, const String &field, const ParserPtr &parser)
virtual void setNextReader(const IndexReaderPtr &reader, int32_t docBase)
Set a new Reader. All doc correspond to the current Reader.
Base class for all Lucene classes.
Definition LuceneObject.h:31
Definition FieldComparator.h:94
Collection< TYPE > values
Definition FieldComparator.h:106
virtual int32_t compare(int32_t slot1, int32_t slot2)
Compare hit at slot1 with hit at slot2.
Definition FieldComparator.h:112
NumericComparator(int32_t numHits, const String &field=EmptyString)
Definition FieldComparator.h:96
virtual ~NumericComparator()
Definition FieldComparator.h:102
virtual void copy(int32_t slot, int32_t doc)
This method is called when a new hit is competitive. You should copy any state associated with this d...
Definition FieldComparator.h:120
virtual void setBottom(int32_t slot)
Set the bottom slot, ie the "weakest" (sorted last) entry in the queue. When compareBottom is called,...
Definition FieldComparator.h:124
Collection< TYPE > currentReaderValues
Definition FieldComparator.h:107
virtual ComparableValue value(int32_t slot)
Return the actual value in the slot.
Definition FieldComparator.h:128
virtual int32_t compareBottom(int32_t doc)
Compare the bottom of the queue with doc. This will only invoked after setBottom has been called....
Definition FieldComparator.h:116
TYPE bottom
Definition FieldComparator.h:109
String field
Definition FieldComparator.h:108
Sorts by descending relevance. NOTE: if you are sorting only by descending relevance and then seconda...
Definition FieldComparator.h:219
virtual void setNextReader(const IndexReaderPtr &reader, int32_t docBase)
Set a new Reader. All doc correspond to the current Reader.
ScorerPtr scorer
Definition FieldComparator.h:227
virtual void setScorer(const ScorerPtr &scorer)
Sets the Scorer to use in case a document's score is needed.
virtual void copy(int32_t slot, int32_t doc)
This method is called when a new hit is competitive. You should copy any state associated with this d...
RelevanceComparator(int32_t numHits)
virtual int32_t compareBottom(int32_t doc)
Compare the bottom of the queue with doc. This will only invoked after setBottom has been called....
virtual int32_t compare(int32_t slot1, int32_t slot2)
Compare hit at slot1 with hit at slot2.
Sorts by a field's value using the Collator for a given Locale.
Definition FieldComparator.h:238
virtual void setNextReader(const IndexReaderPtr &reader, int32_t docBase)
Set a new Reader. All doc correspond to the current Reader.
virtual void setBottom(int32_t slot)
Set the bottom slot, ie the "weakest" (sorted last) entry in the queue. When compareBottom is called,...
virtual int32_t compareBottom(int32_t doc)
Compare the bottom of the queue with doc. This will only invoked after setBottom has been called....
String bottom
Definition FieldComparator.h:250
virtual ComparableValue value(int32_t slot)
Return the actual value in the slot.
String field
Definition FieldComparator.h:248
CollatorPtr collator
Definition FieldComparator.h:249
Collection< String > values
Definition FieldComparator.h:246
Collection< String > currentReaderValues
Definition FieldComparator.h:247
virtual int32_t compare(int32_t slot1, int32_t slot2)
Compare hit at slot1 with hit at slot2.
virtual void copy(int32_t slot, int32_t doc)
This method is called when a new hit is competitive. You should copy any state associated with this d...
StringComparatorLocale(int32_t numHits, const String &field, const std::locale &locale)
Sorts by field's natural String sort order, using ordinals. This is functionally equivalent to String...
Definition FieldComparator.h:266
virtual int32_t compare(int32_t slot1, int32_t slot2)
Compare hit at slot1 with hit at slot2.
int32_t binarySearch(Collection< String > lookup, const String &key, int32_t low, int32_t high)
int32_t sortPos
Definition FieldComparator.h:287
virtual void copy(int32_t slot, int32_t doc)
This method is called when a new hit is competitive. You should copy any state associated with this d...
virtual int32_t getBottomSlot()
virtual Collection< String > getValues()
virtual void setNextReader(const IndexReaderPtr &reader, int32_t docBase)
Set a new Reader. All doc correspond to the current Reader.
bool reversed
Definition FieldComparator.h:286
Collection< int32_t > order
Definition FieldComparator.h:280
Collection< String > lookup
Definition FieldComparator.h:279
String field
Definition FieldComparator.h:281
void convert(int32_t slot)
String bottomValue
Definition FieldComparator.h:285
StringOrdValComparator(int32_t numHits, const String &field, int32_t sortPos, bool reversed)
virtual void setBottom(int32_t slot)
Set the bottom slot, ie the "weakest" (sorted last) entry in the queue. When compareBottom is called,...
Collection< String > values
Definition FieldComparator.h:275
int32_t bottomSlot
Definition FieldComparator.h:283
virtual ComparableValue value(int32_t slot)
Return the actual value in the slot.
int32_t bottomOrd
Definition FieldComparator.h:284
virtual int32_t compareBottom(int32_t doc)
Compare the bottom of the queue with doc. This will only invoked after setBottom has been called....
Collection< int32_t > ords
Definition FieldComparator.h:274
Collection< int32_t > readerGen
Definition FieldComparator.h:276
int32_t currentReaderGen
Definition FieldComparator.h:278
Sorts by field's natural String sort order. All comparisons are done using String....
Definition FieldComparator.h:307
virtual void setBottom(int32_t slot)
Set the bottom slot, ie the "weakest" (sorted last) entry in the queue. When compareBottom is called,...
String bottom
Definition FieldComparator.h:318
virtual ComparableValue value(int32_t slot)
Return the actual value in the slot.
virtual int32_t compare(int32_t slot1, int32_t slot2)
Compare hit at slot1 with hit at slot2.
virtual void setNextReader(const IndexReaderPtr &reader, int32_t docBase)
Set a new Reader. All doc correspond to the current Reader.
Collection< String > currentReaderValues
Definition FieldComparator.h:316
virtual int32_t compareBottom(int32_t doc)
Compare the bottom of the queue with doc. This will only invoked after setBottom has been called....
virtual void copy(int32_t slot, int32_t doc)
This method is called when a new hit is competitive. You should copy any state associated with this d...
StringValComparator(int32_t numHits, const String &field)
Collection< String > values
Definition FieldComparator.h:315
String field
Definition FieldComparator.h:317
Definition AbstractAllTermDocs.h:12
boost::shared_ptr< LongParser > LongParserPtr
Definition LuceneTypes.h:378
boost::shared_ptr< ByteParser > ByteParserPtr
Definition LuceneTypes.h:289
boost::shared_ptr< IntParser > IntParserPtr
Definition LuceneTypes.h:376
boost::shared_ptr< DoubleParser > DoubleParserPtr
Definition LuceneTypes.h:328
boost::shared_ptr< Parser > ParserPtr
Definition LuceneTypes.h:401
boost::shared_ptr< Collator > CollatorPtr
Definition LuceneTypes.h:525
boost::shared_ptr< IndexReader > IndexReaderPtr
Definition LuceneTypes.h:157
boost::shared_ptr< Scorer > ScorerPtr
Definition LuceneTypes.h:429

clucene.sourceforge.net