I tried it to index date with DateTools.dateToString()
method. Its working properly for indexing as well as searching.
But my already indexed data which has some references is in such a way that it has indexed Date as a new Date().getTime()
.
So my problem is how to perform RangeSearch Query
on this data...
Any solution to this???
Thanks in Advance.
You need to use a
TermRangeQuery
on your date field. That field always needs to be indexed withDateTools.dateToString()
for it to work properly. Here's a full example of indexing and searching on a date range with Lucene 3.0:You'll get much better search performance if you use a NumericField for your date, and then NumericRangeFilter/Query to do the range search.
You just have to encode your date as a long or int. One simple way is to call the .getTime() method of your Date, but this may be far more resolution (milli-seconds) than you need. If you only need down to the day, you can encode it as YYYYMMDD integer.
Then, at search time, do the same conversion on your start/end Dates and run NumericRangeQuery/Filter.