You are viewing a plain text version of this content. The canonical link for it is here.
Posted to general@lucene.apache.org by "Kipping, Peter" <Pe...@taylorandfrancis.com> on 2005/04/26 20:18:30 UTC

searching between two fields

Suppose I have a document with two fields, min_temp = 100 and max_temp =
200.  If a user inputs a search value of 150 the document should be
returned.  Is it possible to make this happen with lucene?

Thanks,
Peter


Re: searching between two fields

Posted by Paul Elschot <pa...@xs4all.nl>.
On Tuesday 26 April 2005 20:18, Kipping, Peter wrote:
> Suppose I have a document with two fields, min_temp = 100 and max_temp =
> 200.  If a user inputs a search value of 150 the document should be
> returned.  Is it possible to make this happen with lucene?
> 
> Thanks,
> Peter

Yes, but it would require some extra investments.

The query would be a BooleanQuery of two required RangeQuery's,
with the numbers indexed as strings with zero prefixes to make
the numerical comparison identical to the string comparison used
in by the index.

In case there are a lot of different temperature values to be indexed,
it would probably be good to also index prefixes of some well chosen lengths
of the indexed minimum and maximum temperatures and adapt the  term
enumeration in the RangeQuery to use the prefixes whenever possible.

Regards,
Paul Elschot.


Re: searching between two fields

Posted by Erik Hatcher <er...@ehatchersolutions.com>.
On Apr 26, 2005, at 2:18 PM, Kipping, Peter wrote:
> Suppose I have a document with two fields, min_temp = 100 and max_temp 
> =
> 200.  If a user inputs a search value of 150 the document should be
> returned.  Is it possible to make this happen with lucene?

Yes.

I do this with my work with years.  The data I index has year strings 
like this: "1837-65" but a search for year:1856 will find this 
document.  I do this by expanding the terms indexed so that the year 
field has a term for each year in the range.  In your case, you could 
index a "temp" field with every unit value between 100 and 200 
inclusively.

I recommend you post to java-user@lucene rather than general@lucene.

	Erik