Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>UPDATE</strong>: Like @basZero said in his comment, starting with Lucene 2.9, you can add <a href="http://lucene.apache.org/java/2_9_0/api/core/org/apache/lucene/document/NumericField.html" rel="nofollow noreferrer">numeric fields</a> to your documents. Just remember to use <a href="http://lucene.apache.org/java/2_9_0/api/core/org/apache/lucene/search/NumericRangeQuery.html" rel="nofollow noreferrer">NumericRangeQuery</a> instead of RangeQuery when you search.</p> <h3>Original answer</h3> <p>Lucene treats numbers as words, so their order is alphabetic: </p> <pre><code>0 1 12 123 2 22 </code></pre> <p>That means that for Lucene, 12 is between 0 and 2. If you want to do a proper numerical range, you need to index the numbers zero-padded, then do a range search of [0000 TO 0002]. (The amount of padding you need depends on the expected range of values).</p> <p>If you have negative numbers, just add another zero for non-negative numbers. (EDIT: <strong>WRONG WRONG WRONG</strong>. See update)</p> <p>If your numbers include a fraction part, leave it as is, and zero-pad the integer part only.</p> <p>Example:</p> <p><strike></p> <pre><code>-00002.12 -00001 </code></pre> <p></strike></p> <pre><code>000000 000001 000003.1415 000022 </code></pre> <p><strong>UPDATE</strong>: Negative numbers are a bit tricky, since -1 comes before -2 alphabetically. <a href="http://wiki.apache.org/lucene-java/SearchNumericalFields" rel="nofollow noreferrer">This article</a> gives a complete explanation about dealing with negative numbers and numbers in general in Lucene. Basically, you have to "encode" numbers into something that makes the order of the items make sense.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload