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
12 namespace Lucene {
13
42 class LPPAPI FieldComparator : public LuceneObject {
43 public:
44 virtual ~FieldComparator();
45 LUCENE_CLASS(FieldComparator);
46
47 public:
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
93 template <typename TYPE>
94 class NumericComparator : public FieldComparator {
95 public:
96 NumericComparator(int32_t numHits, const String& field = EmptyString) {
97 this->values = Collection<TYPE>::newInstance(numHits);
98 this->field = field;
99 this->bottom = 0;
100 }
101
102 virtual ~NumericComparator() {
103 }
104
105 protected:
106 Collection<TYPE> values;
107 Collection<TYPE> currentReaderValues;
108 String field;
109 TYPE bottom;
110
111 public:
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
134 class LPPAPI ByteComparator : public NumericComparator<uint8_t> {
135 public:
136 ByteComparator(int32_t numHits, const String& field, const ParserPtr& parser);
137 virtual ~ByteComparator();
138
139 LUCENE_CLASS(ByteComparator);
140
141 protected:
142 ByteParserPtr parser;
143
144 public:
145 virtual void setNextReader(const IndexReaderPtr& reader, int32_t docBase);
146};
147
149 class LPPAPI DocComparator : public NumericComparator<int32_t> {
150 public:
151 DocComparator(int32_t numHits);
152 virtual ~DocComparator();
153
154 LUCENE_CLASS(DocComparator);
155
156 protected:
157 int32_t docBase;
158
159 public:
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
166 class LPPAPI DoubleComparator : public NumericComparator<double> {
167 public:
168 DoubleComparator(int32_t numHits, const String& field, const ParserPtr& parser);
169 virtual ~DoubleComparator();
170
171 LUCENE_CLASS(DoubleComparator);
172
173 protected:
174 DoubleParserPtr parser;
175
176 public:
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
183 class LPPAPI IntComparator : public NumericComparator<int32_t> {
184 public:
185 IntComparator(int32_t numHits, const String& field, const ParserPtr& parser);
186 virtual ~IntComparator();
187
188 LUCENE_CLASS(IntComparator);
189
190 protected:
191 IntParserPtr parser;
192
193 public:
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
200 class LPPAPI LongComparator : public NumericComparator<int64_t> {
201 public:
202 LongComparator(int32_t numHits, const String& field, const ParserPtr& parser);
203 virtual ~LongComparator();
204
205 LUCENE_CLASS(LongComparator);
206
207 protected:
208 LongParserPtr parser;
209
210 public:
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
219 class LPPAPI RelevanceComparator : public NumericComparator<double> {
220 public:
221 RelevanceComparator(int32_t numHits);
222 virtual ~RelevanceComparator();
223
224 LUCENE_CLASS(RelevanceComparator);
225
226 protected:
227 ScorerPtr scorer;
228
229 public:
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
238 class LPPAPI StringComparatorLocale : public FieldComparator {
239 public:
240 StringComparatorLocale(int32_t numHits, const String& field, const std::locale& locale);
241 virtual ~StringComparatorLocale();
242
243 LUCENE_CLASS(StringComparatorLocale);
244
245 protected:
246 Collection<String> values;
247 Collection<String> currentReaderValues;
248 String field;
249 CollatorPtr collator;
250 String bottom;
251
252 public:
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
266 class LPPAPI StringOrdValComparator : public FieldComparator {
267 public:
268 StringOrdValComparator(int32_t numHits, const String& field, int32_t sortPos, bool reversed);
269 virtual ~StringOrdValComparator();
270
271 LUCENE_CLASS(StringOrdValComparator);
272
273 protected:
274 Collection<int32_t> ords;
275 Collection<String> values;
276 Collection<int32_t> readerGen;
277
278 int32_t currentReaderGen;
279 Collection<String> lookup;
280 Collection<int32_t> order;
281 String field;
282
283 int32_t bottomSlot;
284 int32_t bottomOrd;
285 String bottomValue;
286 bool reversed;
287 int32_t sortPos;
288
289 public:
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);
296 virtual Collection<String> getValues();
297 virtual int32_t getBottomSlot();
298 virtual String getField();
299
300 protected:
301 void convert(int32_t slot);
302 int32_t binarySearch(Collection<String> lookup, const String& key, int32_t low, int32_t high);
303};
304
307 class LPPAPI StringValComparator : public FieldComparator {
308 public:
309 StringValComparator(int32_t numHits, const String& field);
310 virtual ~StringValComparator();
311
312 LUCENE_CLASS(StringOrdValComparator);
313
314 protected:
315 Collection<String> values;
316 Collection<String> currentReaderValues;
317 String field;
318 String bottom;
319
320 public:
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
LuceneObject.h
LUCENE_CLASS
#define LUCENE_CLASS(Name)
Definition LuceneObject.h:24
Lucene::ByteComparator::setNextReader
virtual void setNextReader(const IndexReaderPtr &reader, int32_t docBase)
Set a new Reader. All doc correspond to the current Reader.
Lucene::ByteComparator::ByteComparator
ByteComparator(int32_t numHits, const String &field, const ParserPtr &parser)
Lucene::ByteComparator::~ByteComparator
virtual ~ByteComparator()
Lucene::ByteComparator::parser
ByteParserPtr parser
Definition FieldComparator.h:142
Lucene::Collection
Utility template class to handle collections that can be safely copied and shared.
Definition Collection.h:17
Lucene::Collection::newInstance
static this_type newInstance(int32_t size=0)
Definition Collection.h:33
Lucene::DocComparator::~DocComparator
virtual ~DocComparator()
Lucene::DocComparator::copy
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...
Lucene::DocComparator::setNextReader
virtual void setNextReader(const IndexReaderPtr &reader, int32_t docBase)
Set a new Reader. All doc correspond to the current Reader.
Lucene::DocComparator::docBase
int32_t docBase
Definition FieldComparator.h:157
Lucene::DocComparator::DocComparator
DocComparator(int32_t numHits)
Lucene::DocComparator::compareBottom
virtual int32_t compareBottom(int32_t doc)
Compare the bottom of the queue with doc. This will only invoked after setBottom has been called....
Lucene::DoubleComparator::DoubleComparator
DoubleComparator(int32_t numHits, const String &field, const ParserPtr &parser)
Lucene::DoubleComparator::compare
virtual int32_t compare(int32_t slot1, int32_t slot2)
Compare hit at slot1 with hit at slot2.
Lucene::DoubleComparator::~DoubleComparator
virtual ~DoubleComparator()
Lucene::DoubleComparator::parser
DoubleParserPtr parser
Definition FieldComparator.h:174
Lucene::DoubleComparator::compareBottom
virtual int32_t compareBottom(int32_t doc)
Compare the bottom of the queue with doc. This will only invoked after setBottom has been called....
Lucene::DoubleComparator::setNextReader
virtual void setNextReader(const IndexReaderPtr &reader, int32_t docBase)
Set a new Reader. All doc correspond to the current Reader.
Lucene::FieldComparator
A FieldComparator compares hits so as to determine their sort order when collecting the top results w...
Definition FieldComparator.h:42
Lucene::FieldComparator::~FieldComparator
virtual ~FieldComparator()
Lucene::FieldComparator::setScorer
virtual void setScorer(const ScorerPtr &scorer)
Sets the Scorer to use in case a document's score is needed.
Lucene::FieldComparator::compareBottom
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....
Lucene::FieldComparator::copy
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...
Lucene::FieldComparator::setBottom
virtual void setBottom(int32_t slot)=0
Set the bottom slot, ie the "weakest" (sorted last) entry in the queue. When compareBottom is called,...
Lucene::FieldComparator::value
virtual ComparableValue value(int32_t slot)=0
Return the actual value in the slot.
Lucene::FieldComparator::setNextReader
virtual void setNextReader(const IndexReaderPtr &reader, int32_t docBase)=0
Set a new Reader. All doc correspond to the current Reader.
Lucene::FieldComparator::compare
virtual int32_t compare(int32_t slot1, int32_t slot2)=0
Compare hit at slot1 with hit at slot2.
Lucene::IntComparator::parser
IntParserPtr parser
Definition FieldComparator.h:191
Lucene::IntComparator::IntComparator
IntComparator(int32_t numHits, const String &field, const ParserPtr &parser)
Lucene::IntComparator::setNextReader
virtual void setNextReader(const IndexReaderPtr &reader, int32_t docBase)
Set a new Reader. All doc correspond to the current Reader.
Lucene::IntComparator::compare
virtual int32_t compare(int32_t slot1, int32_t slot2)
Compare hit at slot1 with hit at slot2.
Lucene::IntComparator::compareBottom
virtual int32_t compareBottom(int32_t doc)
Compare the bottom of the queue with doc. This will only invoked after setBottom has been called....
Lucene::IntComparator::~IntComparator
virtual ~IntComparator()
Lucene::LongComparator::parser
LongParserPtr parser
Definition FieldComparator.h:208
Lucene::LongComparator::~LongComparator
virtual ~LongComparator()
Lucene::LongComparator::compareBottom
virtual int32_t compareBottom(int32_t doc)
Compare the bottom of the queue with doc. This will only invoked after setBottom has been called....
Lucene::LongComparator::compare
virtual int32_t compare(int32_t slot1, int32_t slot2)
Compare hit at slot1 with hit at slot2.
Lucene::LongComparator::LongComparator
LongComparator(int32_t numHits, const String &field, const ParserPtr &parser)
Lucene::LongComparator::setNextReader
virtual void setNextReader(const IndexReaderPtr &reader, int32_t docBase)
Set a new Reader. All doc correspond to the current Reader.
Lucene::LuceneObject::LuceneObject
LuceneObject()
Lucene::NumericComparator::values
Collection< TYPE > values
Definition FieldComparator.h:106
Lucene::NumericComparator::compare
virtual int32_t compare(int32_t slot1, int32_t slot2)
Compare hit at slot1 with hit at slot2.
Definition FieldComparator.h:112
Lucene::NumericComparator::NumericComparator
NumericComparator(int32_t numHits, const String &field=EmptyString)
Definition FieldComparator.h:96
Lucene::NumericComparator::~NumericComparator
virtual ~NumericComparator()
Definition FieldComparator.h:102
Lucene::NumericComparator::copy
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
Lucene::NumericComparator::setBottom
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
Lucene::NumericComparator::currentReaderValues
Collection< TYPE > currentReaderValues
Definition FieldComparator.h:107
Lucene::NumericComparator::value
virtual ComparableValue value(int32_t slot)
Return the actual value in the slot.
Definition FieldComparator.h:128
Lucene::NumericComparator::compareBottom
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
Lucene::NumericComparator::bottom
TYPE bottom
Definition FieldComparator.h:109
Lucene::NumericComparator::field
String field
Definition FieldComparator.h:108
Lucene::RelevanceComparator::setNextReader
virtual void setNextReader(const IndexReaderPtr &reader, int32_t docBase)
Set a new Reader. All doc correspond to the current Reader.
Lucene::RelevanceComparator::scorer
ScorerPtr scorer
Definition FieldComparator.h:227
Lucene::RelevanceComparator::setScorer
virtual void setScorer(const ScorerPtr &scorer)
Sets the Scorer to use in case a document's score is needed.
Lucene::RelevanceComparator::copy
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...
Lucene::RelevanceComparator::RelevanceComparator
RelevanceComparator(int32_t numHits)
Lucene::RelevanceComparator::compareBottom
virtual int32_t compareBottom(int32_t doc)
Compare the bottom of the queue with doc. This will only invoked after setBottom has been called....
Lucene::RelevanceComparator::~RelevanceComparator
virtual ~RelevanceComparator()
Lucene::RelevanceComparator::compare
virtual int32_t compare(int32_t slot1, int32_t slot2)
Compare hit at slot1 with hit at slot2.
Lucene::StringComparatorLocale::setNextReader
virtual void setNextReader(const IndexReaderPtr &reader, int32_t docBase)
Set a new Reader. All doc correspond to the current Reader.
Lucene::StringComparatorLocale::setBottom
virtual void setBottom(int32_t slot)
Set the bottom slot, ie the "weakest" (sorted last) entry in the queue. When compareBottom is called,...
Lucene::StringComparatorLocale::compareBottom
virtual int32_t compareBottom(int32_t doc)
Compare the bottom of the queue with doc. This will only invoked after setBottom has been called....
Lucene::StringComparatorLocale::bottom
String bottom
Definition FieldComparator.h:250
Lucene::StringComparatorLocale::value
virtual ComparableValue value(int32_t slot)
Return the actual value in the slot.
Lucene::StringComparatorLocale::field
String field
Definition FieldComparator.h:248
Lucene::StringComparatorLocale::collator
CollatorPtr collator
Definition FieldComparator.h:249
Lucene::StringComparatorLocale::~StringComparatorLocale
virtual ~StringComparatorLocale()
Lucene::StringComparatorLocale::values
Collection< String > values
Definition FieldComparator.h:246
Lucene::StringComparatorLocale::currentReaderValues
Collection< String > currentReaderValues
Definition FieldComparator.h:247
Lucene::StringComparatorLocale::compare
virtual int32_t compare(int32_t slot1, int32_t slot2)
Compare hit at slot1 with hit at slot2.
Lucene::StringComparatorLocale::copy
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...
Lucene::StringComparatorLocale::StringComparatorLocale
StringComparatorLocale(int32_t numHits, const String &field, const std::locale &locale)
Lucene::StringOrdValComparator
Sorts by field's natural String sort order, using ordinals. This is functionally equivalent to String...
Definition FieldComparator.h:266
Lucene::StringOrdValComparator::compare
virtual int32_t compare(int32_t slot1, int32_t slot2)
Compare hit at slot1 with hit at slot2.
Lucene::StringOrdValComparator::binarySearch
int32_t binarySearch(Collection< String > lookup, const String &key, int32_t low, int32_t high)
Lucene::StringOrdValComparator::sortPos
int32_t sortPos
Definition FieldComparator.h:287
Lucene::StringOrdValComparator::copy
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...
Lucene::StringOrdValComparator::getBottomSlot
virtual int32_t getBottomSlot()
Lucene::StringOrdValComparator::getValues
virtual Collection< String > getValues()
Lucene::StringOrdValComparator::setNextReader
virtual void setNextReader(const IndexReaderPtr &reader, int32_t docBase)
Set a new Reader. All doc correspond to the current Reader.
Lucene::StringOrdValComparator::reversed
bool reversed
Definition FieldComparator.h:286
Lucene::StringOrdValComparator::order
Collection< int32_t > order
Definition FieldComparator.h:280
Lucene::StringOrdValComparator::lookup
Collection< String > lookup
Definition FieldComparator.h:279
Lucene::StringOrdValComparator::field
String field
Definition FieldComparator.h:281
Lucene::StringOrdValComparator::convert
void convert(int32_t slot)
Lucene::StringOrdValComparator::bottomValue
String bottomValue
Definition FieldComparator.h:285
Lucene::StringOrdValComparator::~StringOrdValComparator
virtual ~StringOrdValComparator()
Lucene::StringOrdValComparator::StringOrdValComparator
StringOrdValComparator(int32_t numHits, const String &field, int32_t sortPos, bool reversed)
Lucene::StringOrdValComparator::setBottom
virtual void setBottom(int32_t slot)
Set the bottom slot, ie the "weakest" (sorted last) entry in the queue. When compareBottom is called,...
Lucene::StringOrdValComparator::values
Collection< String > values
Definition FieldComparator.h:275
Lucene::StringOrdValComparator::bottomSlot
int32_t bottomSlot
Definition FieldComparator.h:283
Lucene::StringOrdValComparator::value
virtual ComparableValue value(int32_t slot)
Return the actual value in the slot.
Lucene::StringOrdValComparator::bottomOrd
int32_t bottomOrd
Definition FieldComparator.h:284
Lucene::StringOrdValComparator::compareBottom
virtual int32_t compareBottom(int32_t doc)
Compare the bottom of the queue with doc. This will only invoked after setBottom has been called....
Lucene::StringOrdValComparator::ords
Collection< int32_t > ords
Definition FieldComparator.h:274
Lucene::StringOrdValComparator::readerGen
Collection< int32_t > readerGen
Definition FieldComparator.h:276
Lucene::StringOrdValComparator::getField
virtual String getField()
Lucene::StringOrdValComparator::currentReaderGen
int32_t currentReaderGen
Definition FieldComparator.h:278
Lucene::StringValComparator::setBottom
virtual void setBottom(int32_t slot)
Set the bottom slot, ie the "weakest" (sorted last) entry in the queue. When compareBottom is called,...
Lucene::StringValComparator::bottom
String bottom
Definition FieldComparator.h:318
Lucene::StringValComparator::value
virtual ComparableValue value(int32_t slot)
Return the actual value in the slot.
Lucene::StringValComparator::compare
virtual int32_t compare(int32_t slot1, int32_t slot2)
Compare hit at slot1 with hit at slot2.
Lucene::StringValComparator::setNextReader
virtual void setNextReader(const IndexReaderPtr &reader, int32_t docBase)
Set a new Reader. All doc correspond to the current Reader.
Lucene::StringValComparator::~StringValComparator
virtual ~StringValComparator()
Lucene::StringValComparator::currentReaderValues
Collection< String > currentReaderValues
Definition FieldComparator.h:316
Lucene::StringValComparator::compareBottom
virtual int32_t compareBottom(int32_t doc)
Compare the bottom of the queue with doc. This will only invoked after setBottom has been called....
Lucene::StringValComparator::copy
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...
Lucene::StringValComparator::StringValComparator
StringValComparator(int32_t numHits, const String &field)
Lucene::StringValComparator::values
Collection< String > values
Definition FieldComparator.h:315
Lucene::StringValComparator::field
String field
Definition FieldComparator.h:317
Lucene
Definition AbstractAllTermDocs.h:12
Lucene::IntParserPtr
boost::shared_ptr< IntParser > IntParserPtr
Definition LuceneTypes.h:376
Lucene::DoubleParserPtr
boost::shared_ptr< DoubleParser > DoubleParserPtr
Definition LuceneTypes.h:328
Lucene::LongParserPtr
boost::shared_ptr< LongParser > LongParserPtr
Definition LuceneTypes.h:378
Lucene::ByteParserPtr
boost::shared_ptr< ByteParser > ByteParserPtr
Definition LuceneTypes.h:289
Lucene::CollatorPtr
boost::shared_ptr< Collator > CollatorPtr
Definition LuceneTypes.h:525
Lucene::ParserPtr
boost::shared_ptr< Parser > ParserPtr
Definition LuceneTypes.h:401
Lucene::ScorerPtr
boost::shared_ptr< Scorer > ScorerPtr
Definition LuceneTypes.h:429
Lucene::IndexReaderPtr
boost::shared_ptr< IndexReader > IndexReaderPtr
Definition LuceneTypes.h:157

clucene.sourceforge.net