0
votes

For example, I have some documents described by fields: id, date and price.

First document: id=1, date='from 10.01.2014 to 20.01.2014', price='120'

Second document: id=2, date='19.01.2014' and price='from 100 to 140'

My program receives key/value parameters and should find the most suitable documents. So, for example, with this parameters date=19.01.2014 and price='120' program should find both documents. With date=20.01.2014, price=120' only the first document. With date='19.01.2014, price=140' only the second one.

How can I do it with Lucene in Java? I saw examples where I'm typing query like 'give me docs where date is from .. to ..', and Lucene gives me docs in this range. Instead of this I want to specify range for my document and not for query.

1

1 Answers

1
votes

You could index both opening and closing ranges for dates and prices, e.g.

Your document #1 would be indexed as:

id = 1
dateFrom = 10.01.2014 
dateTo = 20.01.2014 
priceFrom = 120
priceTo = 9999999999

And document #2 as

id=2
dateFrom = 19.01.2014
dateTo = 01.01.2099
priceFrom = 100
priceTo = 140

The query would look like this:

+dateFrom:[19.01.2014 TO *] +priceFrom:[120 TO *] +priceTo:[* TO 140]

This is not very effective but it should work.