UPDATE . Like @basZero in your comment, starting with Lucene 2.9, you can add number fields to your documents. Just remember to use NumericRangeQuery instead of RangeQuery when searching.
Original answer
Lucene treats numbers as words, so their order is literal:
0 1 12 123 2 22
This means that for Lucene 12 is between 0 and 2. If you want to make the correct number range, you need to index the numbers with zero margin, and then search for the range in the range from [0000 to 0002]. (The number of additions required depends on the expected range of values).
If you have negative numbers, just add another zero for non-negative numbers. (EDIT: INCORRECT INCORRECT . See Update)
If your numbers contain part of the fractions, leave it as it is, and the null pad only the whole part.
Example:
-00002.12 -00001
Strike>
000000 000001 000003.1415 000022
UPDATE Negative numbers are a bit complicated, as -1 to -2 in alphabetical order. This article gives a complete explanation regarding negative numbers and numbers in general in Lucene. Basically, you should βencodeβ numbers into something that makes the order of the elements understandable.
itsadok
source share