1
votes

I am searching for documents in Lucene index whose start time field value is less than or equal to my time (t) and finish time field value is greater than my time(t). Here start time, finish time and my time all are in hh:mm format. I have converted all of them to a integral value that is equal to hh*60+mm. Now I want to check whether value of my time lies in the range between the value associated with start time and value associated with finish time.

But here I have encountered several problems. they are as follows:

1.I cannot add fields with integral values to an index.

2.I cannot understand how to form this range query in Lucene involving integers.

So if anyone helps me to solve this I will be grateful Thank you.

1

1 Answers

0
votes

1: Use IntField, for instance:

document.add(new IntField("starttime", 1234, Field.Store.YES));

2: The query parser now supports Numeric Range queries, simply like starttime:[1234 TO 1345], or you can create a NumericRangeQuery yourself, like:

Query rangeQuery = NumericRangeQuery.newIntRange("starttime", 1234, 1345, false, false);

Or for a greater than, a range can be open by passing a null for one of the values.

Query rangeQuery = NumericRangeQuery.newIntRange("starttime", 1234, null, false, false);