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

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

- File List
- Globals

All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
FieldComparator.h
Go to the documentation of this file.
1 // Copyright (c) 2009-2011 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 {
44 public:
45 virtual ~FieldComparator();
46 LUCENE_CLASS(FieldComparator);
47
48 public:
54 virtual int32_t compare(int32_t slot1, int32_t slot2) = 0;
55
59 virtual void setBottom(int32_t slot) = 0;
60
70 virtual int32_t compareBottom(int32_t doc) = 0;
71
76 virtual void copy(int32_t slot, int32_t doc) = 0;
77
82 virtual void setNextReader(IndexReaderPtr reader, int32_t docBase) = 0;
83
86 virtual void setScorer(ScorerPtr scorer);
87
91 virtual ComparableValue value(int32_t slot) = 0;
92 };
93
94 template <typename TYPE>
95 class NumericComparator : public FieldComparator
96 {
97 public:
98 NumericComparator(int32_t numHits, const String& field = EmptyString)
99 {
100 this->values = Collection<TYPE>::newInstance(numHits);
101 this->field = field;
102 this->bottom = 0;
103 }
104
105 virtual ~NumericComparator()
106 {
107 }
108
109 protected:
110 Collection<TYPE> values;
111 Collection<TYPE> currentReaderValues;
112 String field;
113 TYPE bottom;
114
115 public:
116 virtual int32_t compare(int32_t slot1, int32_t slot2)
117 {
118 return (int32_t)(values[slot1] - values[slot2]);
119 }
120
121 virtual int32_t compareBottom(int32_t doc)
122 {
123 return (int32_t)(bottom - currentReaderValues[doc]);
124 }
125
126 virtual void copy(int32_t slot, int32_t doc)
127 {
128 values[slot] = currentReaderValues[doc];
129 }
130
131 virtual void setBottom(int32_t slot)
132 {
133 bottom = values[slot];
134 }
135
136 virtual ComparableValue value(int32_t slot)
137 {
138 return ComparableValue(values[slot]);
139 }
140 };
141
143 class LPPAPI ByteComparator : public NumericComparator<uint8_t>
144 {
145 public:
146 ByteComparator(int32_t numHits, const String& field, ParserPtr parser);
147 virtual ~ByteComparator();
148
149 LUCENE_CLASS(ByteComparator);
150
151 protected:
152 ByteParserPtr parser;
153
154 public:
155 virtual void setNextReader(IndexReaderPtr reader, int32_t docBase);
156 };
157
159 class LPPAPI DocComparator : public NumericComparator<int32_t>
160 {
161 public:
162 DocComparator(int32_t numHits);
163 virtual ~DocComparator();
164
165 LUCENE_CLASS(DocComparator);
166
167 protected:
168 int32_t docBase;
169
170 public:
171 virtual int32_t compareBottom(int32_t doc);
172 virtual void copy(int32_t slot, int32_t doc);
173 virtual void setNextReader(IndexReaderPtr reader, int32_t docBase);
174 };
175
177 class LPPAPI DoubleComparator : public NumericComparator<double>
178 {
179 public:
180 DoubleComparator(int32_t numHits, const String& field, ParserPtr parser);
181 virtual ~DoubleComparator();
182
183 LUCENE_CLASS(DoubleComparator);
184
185 protected:
186 DoubleParserPtr parser;
187
188 public:
189 virtual int32_t compare(int32_t slot1, int32_t slot2);
190 virtual int32_t compareBottom(int32_t doc);
191 virtual void setNextReader(IndexReaderPtr reader, int32_t docBase);
192 };
193
195 class LPPAPI IntComparator : public NumericComparator<int32_t>
196 {
197 public:
198 IntComparator(int32_t numHits, const String& field, ParserPtr parser);
199 virtual ~IntComparator();
200
201 LUCENE_CLASS(IntComparator);
202
203 protected:
204 IntParserPtr parser;
205
206 public:
207 virtual int32_t compare(int32_t slot1, int32_t slot2);
208 virtual int32_t compareBottom(int32_t doc);
209 virtual void setNextReader(IndexReaderPtr reader, int32_t docBase);
210 };
211
213 class LPPAPI LongComparator : public NumericComparator<int64_t>
214 {
215 public:
216 LongComparator(int32_t numHits, const String& field, ParserPtr parser);
217 virtual ~LongComparator();
218
219 LUCENE_CLASS(LongComparator);
220
221 protected:
222 LongParserPtr parser;
223
224 public:
225 virtual int32_t compare(int32_t slot1, int32_t slot2);
226 virtual int32_t compareBottom(int32_t doc);
227 virtual void setNextReader(IndexReaderPtr reader, int32_t docBase);
228 };
229
233 class LPPAPI RelevanceComparator : public NumericComparator<double>
234 {
235 public:
236 RelevanceComparator(int32_t numHits);
237 virtual ~RelevanceComparator();
238
239 LUCENE_CLASS(RelevanceComparator);
240
241 protected:
242 ScorerPtr scorer;
243
244 public:
245 virtual int32_t compare(int32_t slot1, int32_t slot2);
246 virtual int32_t compareBottom(int32_t doc);
247 virtual void copy(int32_t slot, int32_t doc);
248 virtual void setNextReader(IndexReaderPtr reader, int32_t docBase);
249 virtual void setScorer(ScorerPtr scorer);
250 };
251
253 class LPPAPI StringComparatorLocale : public FieldComparator
254 {
255 public:
256 StringComparatorLocale(int32_t numHits, const String& field, const std::locale& locale);
257 virtual ~StringComparatorLocale();
258
259 LUCENE_CLASS(StringComparatorLocale);
260
261 protected:
262 Collection<String> values;
263 Collection<String> currentReaderValues;
264 String field;
265 CollatorPtr collator;
266 String bottom;
267
268 public:
269 virtual int32_t compare(int32_t slot1, int32_t slot2);
270 virtual int32_t compareBottom(int32_t doc);
271 virtual void copy(int32_t slot, int32_t doc);
272 virtual void setNextReader(IndexReaderPtr reader, int32_t docBase);
273 virtual void setBottom(int32_t slot);
274 virtual ComparableValue value(int32_t slot);
275 };
276
282 class LPPAPI StringOrdValComparator : public FieldComparator
283 {
284 public:
285 StringOrdValComparator(int32_t numHits, const String& field, int32_t sortPos, bool reversed);
286 virtual ~StringOrdValComparator();
287
288 LUCENE_CLASS(StringOrdValComparator);
289
290 protected:
291 Collection<int32_t> ords;
292 Collection<String> values;
293 Collection<int32_t> readerGen;
294
295 int32_t currentReaderGen;
296 Collection<String> lookup;
297 Collection<int32_t> order;
298 String field;
299
300 int32_t bottomSlot;
301 int32_t bottomOrd;
302 String bottomValue;
303 bool reversed;
304 int32_t sortPos;
305
306 public:
307 virtual int32_t compare(int32_t slot1, int32_t slot2);
308 virtual int32_t compareBottom(int32_t doc);
309 virtual void copy(int32_t slot, int32_t doc);
310 virtual void setNextReader(IndexReaderPtr reader, int32_t docBase);
311 virtual void setBottom(int32_t slot);
312 virtual ComparableValue value(int32_t slot);
313 virtual Collection<String> getValues();
314 virtual int32_t getBottomSlot();
315 virtual String getField();
316
317 protected:
318 void convert(int32_t slot);
319 int32_t binarySearch(Collection<String> lookup, const String& key, int32_t low, int32_t high);
320 };
321
324 class LPPAPI StringValComparator : public FieldComparator
325 {
326 public:
327 StringValComparator(int32_t numHits, const String& field);
328 virtual ~StringValComparator();
329
330 LUCENE_CLASS(StringOrdValComparator);
331
332 protected:
333 Collection<String> values;
334 Collection<String> currentReaderValues;
335 String field;
336 String bottom;
337
338 public:
339 virtual int32_t compare(int32_t slot1, int32_t slot2);
340 virtual int32_t compareBottom(int32_t doc);
341 virtual void copy(int32_t slot, int32_t doc);
342 virtual void setNextReader(IndexReaderPtr reader, int32_t docBase);
343 virtual void setBottom(int32_t slot);
344 virtual ComparableValue value(int32_t slot);
345 };
346 }
347
348 #endif

clucene.sourceforge.net