3

We are currently using lucene 2.3.2. We pad integers with leading zeroes and index so that we can support range queries as well. We are working towards upgrading to lucene 3.4 and want to use NumericRangeQueries. We also want to support non-range queries on numeric fields. Is there any way to use number field and support in-list kind of queries on numeric fields in lucene.

request_id:(123, 124, 253)

I know that above query can be translated to

request_id:[123 TO 123] OR request_id:[124 TO 124] OR request_id:[253 TO 253]

But query will be too long when user gives a huge list. Is there any way to get the best of both approaches? (performance benefits on range queries from indexing as numeric fields and supporting in-list queries without translating these to pseudo range queries)

naresh
  • 2,113
  • 20
  • 32

1 Answers1

0

It appears that you have to use org.apache.lucene.util.NumericUtils to accomplish this, such as:

new TermQuery(new Term("field",
NumericUtils.intToPrefixCoded(myInt)));

Although, from what I understand, it should be optimized to handle range queries with equal min and max, so the example query you provided should not incur any more overhead than the example here.

femtoRgon
  • 32,893
  • 7
  • 60
  • 87