views:

45

answers:

1

I'm using Lucene, and I'm trying to find a way to index and retrieve documents that have a ranged property.

For example I have:

Document 1: Price:[30 TO 50]
Document 2: Price:[45 TO 60]
Document 3: Price:[60 TO 70]

And I would like to search for all the documents whose ranges intersect a specific interval, in the above example, if I search for Price in [55 TO 65] I should get Document 2 and Document 3 as results.

I don't think NumericRangeQueries alone would do the trick, I need to work on the index with something similar to R-trees, but are they implemented in Lucene? Also, I suppose that what I need should be a subclass of MultiTermQuery, because the query Price in [55 TO 65] has two boundaries, but I don't see anything suitable among MultiTermQuery's subclasses.

Any help is appreciated, thanks,

Silvio

P.S. I'm using Lucene 2.9.0, but I can update to the latest release if needed.

+1  A: 

One simple option to try is, during index time, simply expand your ranges to each discrete value in the range. So [30 TO 50] would be indexed as 30, 31, 32, 33, 34, etc. Then use the normal range query to query the range. Just as long as there aren't tons of discrete values (millions) this might perform well enough.

bajafresh4life
That way I would be tied to the number of values I use to discretize the intervals, also it would generate a lot of fields (one for each discrete value), which would bloat my document schema. It's a possible solution, of course, but I'd keep it as a last resort
Silvio Donnini
You don't need to create separate fields. All values would go in the same field, no change to document schema needed.
bajafresh4life