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


NumericUtils.h
Go to the documentation of this file.
1 // 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 NUMERICUTILS_H
8 #define NUMERICUTILS_H
9 
10 #include "LuceneObject.h"
11 
12 namespace Lucene {
13 
37 class LPPAPI NumericUtils : public LuceneObject {
38 public:
39  virtual ~NumericUtils();
40 
42 
43 public:
46  static const int32_t PRECISION_STEP_DEFAULT;
47 
50  static const wchar_t SHIFT_START_LONG;
51 
54  static const int32_t BUF_SIZE_LONG;
55 
58  static const wchar_t SHIFT_START_INT;
59 
62  static const int32_t BUF_SIZE_INT;
63 
64 public:
71  static int32_t longToPrefixCoded(int64_t val, int32_t shift, CharArray buffer);
72 
77  static String longToPrefixCoded(int64_t val, int32_t shift);
78 
82  static String longToPrefixCoded(int64_t val);
83 
90  static int32_t intToPrefixCoded(int32_t val, int32_t shift, CharArray buffer);
91 
96  static String intToPrefixCoded(int32_t val, int32_t shift);
97 
101  static String intToPrefixCoded(int32_t val);
102 
106  static int64_t prefixCodedToLong(const String& prefixCoded);
107 
111  static int32_t prefixCodedToInt(const String& prefixCoded);
112 
117  static int64_t doubleToSortableLong(double val);
118 
120  static String doubleToPrefixCoded(double val);
121 
124  static double sortableLongToDouble(int64_t val);
125 
127  static double prefixCodedToDouble(const String& val);
128 
132  static void splitLongRange(const LongRangeBuilderPtr& builder, int32_t precisionStep, int64_t minBound, int64_t maxBound);
133 
137  static void splitIntRange(const IntRangeBuilderPtr& builder, int32_t precisionStep, int32_t minBound, int32_t maxBound);
138 
140  static void splitRange(const LuceneObjectPtr& builder, int32_t valSize, int32_t precisionStep, int64_t minBound, int64_t maxBound);
141 
143  static void addRange(const LuceneObjectPtr& builder, int32_t valSize, int64_t minBound, int64_t maxBound, int32_t shift);
144 };
145 
148 class LPPAPI LongRangeBuilder : public LuceneObject {
149 public:
150  virtual ~LongRangeBuilder();
151 
152 public:
155  virtual void addRange(const String& minPrefixCoded, const String& maxPrefixCoded);
156 
159  virtual void addRange(int64_t min, int64_t max, int32_t shift);
160 };
161 
162 class LPPAPI IntRangeBuilder : public LuceneObject {
163 public:
164  virtual ~IntRangeBuilder();
165 
166 public:
169  virtual void addRange(const String& minPrefixCoded, const String& maxPrefixCoded);
170 
173  virtual void addRange(int32_t min, int32_t max, int32_t shift);
174 };
175 
176 }
177 
178 #endif
#define LUCENE_CLASS(Name)
Definition: LuceneObject.h:24
Definition: NumericUtils.h:162
virtual void addRange(const String &minPrefixCoded, const String &maxPrefixCoded)
Overwrite this method, if you like to receive the already prefix encoded range bounds....
virtual void addRange(int32_t min, int32_t max, int32_t shift)
Overwrite this method, if you like to receive the raw int range bounds. You can use this for eg....
Callback for splitLongRange. You need to overwrite only one of the methods. NOTE: This is a very low-...
Definition: NumericUtils.h:148
virtual void addRange(int64_t min, int64_t max, int32_t shift)
Overwrite this method, if you like to receive the raw long range bounds. You can use this for eg....
virtual void addRange(const String &minPrefixCoded, const String &maxPrefixCoded)
Overwrite this method, if you like to receive the already prefix encoded range bounds....
Base class for all Lucene classes.
Definition: LuceneObject.h:31
This is a helper class to generate prefix-encoded representations for numerical values and supplies c...
Definition: NumericUtils.h:37
static double sortableLongToDouble(int64_t val)
Converts a sortable long back to a double.
static void splitIntRange(const IntRangeBuilderPtr &builder, int32_t precisionStep, int32_t minBound, int32_t maxBound)
Splits an int32_t range recursively. You may implement a builder that adds clauses to a BooleanQuery ...
static const wchar_t SHIFT_START_INT
Integers are stored at lower precision by shifting off lower bits. The shift count is stored as SHIFT...
Definition: NumericUtils.h:58
static int32_t intToPrefixCoded(int32_t val, int32_t shift, CharArray buffer)
Returns prefix coded bits after reducing the precision by shift bits. This is method is used by {}.
static int64_t doubleToSortableLong(double val)
Converts a double value to a sortable signed long. The value is converted by getting their IEEE 754 f...
static int32_t prefixCodedToInt(const String &prefixCoded)
Returns an int from prefixCoded characters. Rightmost bits will be zero for lower precision codes....
static const int32_t BUF_SIZE_LONG
The maximum term length (used for char[] buffer size) for encoding long values.
Definition: NumericUtils.h:54
static String longToPrefixCoded(int64_t val, int32_t shift)
Returns prefix coded bits after reducing the precision by shift bits. This is method is used by LongR...
static double prefixCodedToDouble(const String &val)
Convenience method: this just returns: sortableLongToDouble(prefixCodedToLong(val))
static int32_t longToPrefixCoded(int64_t val, int32_t shift, CharArray buffer)
Returns prefix coded bits after reducing the precision by shift bits. This is method is used by Numer...
static const int32_t BUF_SIZE_INT
The maximum term length (used for char[] buffer size) for encoding int values.
Definition: NumericUtils.h:62
static const int32_t PRECISION_STEP_DEFAULT
The default precision step used by NumericField, NumericTokenStream, NumericRangeQuery,...
Definition: NumericUtils.h:41
static void splitRange(const LuceneObjectPtr &builder, int32_t valSize, int32_t precisionStep, int64_t minBound, int64_t maxBound)
This helper does the splitting for both 32 and 64 bit.
static String doubleToPrefixCoded(double val)
Convenience method: this just returns: longToPrefixCoded(doubleToSortableLong(val))
static String longToPrefixCoded(int64_t val)
This is a convenience method, that returns prefix coded bits of a long without reducing the precision...
static String intToPrefixCoded(int32_t val)
This is a convenience method, that returns prefix coded bits of an int without reducing the precision...
static String intToPrefixCoded(int32_t val, int32_t shift)
Returns prefix coded bits after reducing the precision by shift bits. This is method is used by {}.
static const wchar_t SHIFT_START_LONG
Longs are stored at lower precision by shifting off lower bits. The shift count is stored as SHIFT_ST...
Definition: NumericUtils.h:50
static void splitLongRange(const LongRangeBuilderPtr &builder, int32_t precisionStep, int64_t minBound, int64_t maxBound)
Splits a int64_t range recursively. You may implement a builder that adds clauses to a BooleanQuery f...
static int64_t prefixCodedToLong(const String &prefixCoded)
Returns a long from prefixCoded characters. Rightmost bits will be zero for lower precision codes....
static void addRange(const LuceneObjectPtr &builder, int32_t valSize, int64_t minBound, int64_t maxBound, int32_t shift)
Helper that delegates to correct range builder.
Definition: AbstractAllTermDocs.h:12
boost::shared_ptr< LuceneObject > LuceneObjectPtr
Definition: LuceneTypes.h:539
boost::shared_ptr< LongRangeBuilder > LongRangeBuilderPtr
Definition: LuceneTypes.h:538
boost::shared_ptr< IntRangeBuilder > IntRangeBuilderPtr
Definition: LuceneTypes.h:537

clucene.sourceforge.net