Numeric Datatype
Edit pageThe following Numeric types are supported:
|---------------------------------------|-------------------------------------------------------------------------------|
| _integer | A 64 bit signed integer type |
| _positive | A 64 bit unsigned integer type |
| _float | A double-precision 64-bit IEEE 754 floating point number, restricted to finite values |
Exact Values
Section titled “Exact Values”A numeric field takes only values of its type, and so does a numeric _id: in a write, in a search term, in a range
bound and in q=. A number qualifies when it is exactly a value of the type: 12 and 12.0 are integers, 1.5 is not,
-1 is not a _positive, and 2^63 is out of range for an _integer. Text that spells such a number is the number
("12", not " 12"). An integral float of 2^53 or more is no integer, since a fraction can round to it
(9007199254740993.5 reads as 9007199254740994.0); text spelling such an integer exactly ("9007199254740993") is. Anything
else answers 400, with a message naming the field, the value and the type; nothing is truncated, wrapped, or searched as
something else.
PUT /exactvalues/1
{ "count": { "_type": "integer", "_value": 12 }}PUT /exactvalues/2
{ "count": "13"}PUT /exactvalues/3
{ "count": 1.5}The IDs of this index are integers, set by its first document, so an ID is held to the same rule. Here a restore
names each document’s _id in its body; the second one is refused and the others are written:
RESTORE /exactvalues/
[ { "_id": 4, "count": 4 }, { "_id": 1.5, "count": 1 }, { "_id": "5", "count": 5 }]A search holds its values to the field’s type the same way. An exact value matches:
SEARCH /exactvalues/
{ "_query": { "count": "13" }}A value of another type answers 400, in a term, a range bound and q=:
SEARCH /exactvalues/
{ "_query": { "_id": "abc" }}SEARCH /exactvalues/
{ "_query": { "count": { "_in": { "_range": { "_from": 1.5, "_to": 20 } } } }}SEARCH /exactvalues/?q=count:1.5To convert a value on purpose, cast it (see Casting Values):
{"_integer": 12.7} is 12. A cast converts types; it does not wrap, so {"_positive": -1} is still a 400.
SEARCH /exactvalues/
{ "_query": { "count": { "_integer": 12.7 } }}Sources: Serialize::exact in src/serialize.cc, called by the writes (src/database/schema.cc), the searches
(src/query_dsl.cc) and the numeric IDs (Serialize::id); the casts, src/cast.cc.
Accuracy
Section titled “Accuracy”Xapiand handles numerical ranges by trie indexing numerical values in a special string-encoded format with variable precision.
All numerical (and also dates, times and geospatial) values are converted to lexicographic sortable string representations and indexed with different precisions. A range of values 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.
Default accuracy in numeric fields is:
[ 100, 1000, 10000, 100000, 1000000, 100000000 ]Parameters
Section titled “Parameters”The following parameters are accepted by Numeric fields:
|---------------------------------------|-----------------------------------------------------------------------------------------|
| _accuracy | Array with the accuracies to be indexed. (Array of numeric values). |
| _value | The value for the field. (Only used at index time). |
| _index | The mode the field will be indexed as: "none", "field_terms", "field_values", "field_all", "field", "global_terms", "global_values", "global_all", "global", "terms", "values", "all". (The default is "field_all"). |
| _slot | The slot number. (It’s calculated by default). |
| _prefix | The prefix the term is going to be indexed with. (It’s calculated by default) |
| _weight | The weight the term is going to be indexed with. |