This is a helper class to generate prefix-encoded representations for numerical values and supplies converters to represent float/double values as sortable integers/longs.

To quickly execute range queries in Apache Lucene, a range is divided recursively into multiple intervals for searching: The center of the range is searched only with the lowest possible precision in the trie, while the boundaries are matched more exactly. This reduces the number of terms dramatically.

This class generates terms to achive this: First the numerical integer values need to be converted to strings. For that integer values (32 bit or 64 bit) are made unsigned and the bits are converted to ASCII chars with each 7 bit. The resulting string is sortable like the original integer value. Each value is also prefixed (in the first char) by the

CopyC#
shift
value (number of bits removed) used during encoding.

To also index floating point numbers, this class supplies two methods to convert them to integer values by changing their bit layout: {@link #doubleToSortableLong}, {@link #floatToSortableInt}. You will have no precision loss by converting floating point numbers to integers and back (only that the integer form is not usable). Other data types like dates can easily converted to longs or ints (e.g. date to long: {@link java.util.Date#getTime}).

For easy usage, the trie algorithm is implemented for indexing inside {@link NumericTokenStream} that can index

CopyC#
int
,
CopyC#
long
,
CopyC#
float
, and
CopyC#
double
. For querying, {@link NumericRangeQuery} and {@link NumericRangeFilter} implement the query part for the same data types.

This class can also be used, to generate lexicographically sortable (according {@link String#compareTo(String)}) representations of numeric data types for other usages (e.g. sorting).

NOTE: This API is experimental and might change in incompatible ways in the next release.

Namespace: Lucene.Net.Util
Assembly: Lucene.Net (in Lucene.Net.dll) Version: 2.9.4.1

Syntax

C#
public sealed class NumericUtils
Visual Basic
Public NotInheritable Class NumericUtils
Visual C++
public ref class NumericUtils sealed

Inheritance Hierarchy

System..::..Object
  Lucene.Net.Util..::..NumericUtils

See Also