Lucene query language and numeric range

1.2k Views Asked by At

I'm applying the following Lucene query predicate in order to get all inclusive numbers in 2 to 6 range:

value:[2 TO 6]

and receive the documents with the following values:

567986400000
567986400000
567986400000
536450400000
536450400000
599608800000
536450400000
567986400000

I'm interested in the numeric range query and obviously, for example, the Long value 567986400000 is not in the range of [2 TO 6]. Looks like the range searches are strings and I don't know how to workaround it in mine application for the different numeric values.

How to properly use numeric range queries in Lucene?

1

There are 1 best solutions below

0
On BEST ANSWER

To achieve a proper range query you need to use specific defined fields from lucene. See Field javadoc

  • IntPoint: int indexed for exact/range queries.
  • LongPoint: long indexed for exact/range queries.
  • FloatPoint: float indexed for exact/range queries.
  • DoublePoint: double indexed for exact/range queries.

So you need to be sure that your field you add this query is one of this types. As you said you use a Neo4j generated lucene index. There has to be an option to create this kind of fields otherwise you're not able to execute proper range queries.