Ahh yes, that is a good article.  I inadvertently missed the need to
invert the magnitude of negative numbers in the recipe below (I don't
have negatives in any of my fiels).  Fortunately that is also easy to
do.

FYI, you don't need a custom query parser for range queries.  That's
only required if you expect your users to type in range query syntax (so
that you have to convert their numbers to your formatted
representation).  Rather than expect the user to type in that syntax, I
provide text input fields for the range bounds in range-searchable
fields.  You can then either generate standard range query syntax (using
the string-formatted encoding of numbers) or generate the RangeQuery
objects directly, depending on how you are constructing your queries
(with or without QueryParser).  

Chuck

> -----Original Message-----
> From: sam s [mailto:[EMAIL PROTECTED]
> Sent: Thursday, October 14, 2004 11:22 AM
> To: [EMAIL PROTECTED]
> Subject: RE: Filtering Results?
> 
> Thanks Chuck.
> Meanwhile searching on net and found this link
> http://wiki.apache.org/jakarta-lucene/SearchNumericalFields
> Thanks again
> 
> 
> >From: "Chuck Williams" <[EMAIL PROTECTED]>
> >Reply-To: "Lucene Users List" <[EMAIL PROTECTED]>
> >To: "Lucene Users List" <[EMAIL PROTECTED]>
> >Subject: RE: Filtering Results?
> >Date: Thu, 14 Oct 2004 09:55:07 -0700
> >
> >Sam,
> >
> >You can pick any encoding such that lexicographic order (alphabetic
> >order) is consistent with the numeric order you want.  E.g., if a
single
> >field can contain positive or negative integers or floats, then the
> >following should work:
> >1.  First character of every value represents the sign.  You can't
use +
> >and - since + is alphabetically before - (which would make positives
> >smaller than negatives), so pick a different character to represent +
> >like maybe =.
> >2.  Characters 2 through n are a fixed length string that presents
the
> >integer part of the number, padded with leading zeroes.
> >3.  You don't need padding on the right since longer strings
> >alphabetically follow shorter strings.  Just included the decimal
point
> >if the number is float, and trail out whatever remaining digits
> >naturally print.
> >4.  One other subtlety occurs if you need to ensure that 2 and 2.0
are
> >equal.  You need to transform one to the other (if you can have both
> >integers and floats in a single field -- otherwise this is not an
> >issue).  You will lose information about the original type.
> >
> >I haven't tested the above, but think it should work.
> >
> >Chuck
> >
> > > -----Original Message-----
> > > From: sam s [mailto:[EMAIL PROTECTED]
> > > Sent: Thursday, October 14, 2004 6:40 AM
> > > To: [EMAIL PROTECTED]
> > > Subject: RE: Filtering Results?
> > >
> > > Thanks Chuck.
> > >
> > > What is the workaround for filtering (preferably using RangeQuery)
> > > following?
> > > 1. Float values. Do I have to pad those with zeros on both sides?
> > > 2. Negative numbers (integer as well as floats)
> > >
> > > Thanks
> > >
> > > >From: "Chuck Williams" <[EMAIL PROTECTED]>
> > > >Reply-To: "Lucene Users List" <[EMAIL PROTECTED]>
> > > >To: "Lucene Users List" <[EMAIL PROTECTED]>
> > > >Subject: RE: Filtering Results?
> > > >Date: Wed, 13 Oct 2004 21:49:30 -0700
> > > >
> > > >RangeQuery is a good approach.  Put fields on your documents like
> >age.
> > > >The only tricky thing is that the comparisons are all done
> > > >lexicographically rather that numerically.  Lucene has a built-in
> > > >routine to convert dates into a monotonic lexicographic sequence
> > > >(DateField.timeToString).  For positive integer data types like
age,
> >it
> > > >is sufficient to store them as fixed line String's, e.g.:
> > > >   5 --> "005"
> > > >  18 --> "018"
> > > >100 --> "100"
> > > >
> > > >Then just access range queries.  E.g.:
> > > >1.  age:[018 TO]
> > > >2.  age:[TO 018]
> > > >3.  age:[005 TO 018]
> > > >
> > > >Those are <= queries.  Use {} instead of [] for < queries.
> > > >
> > > >Good luck,
> > > >
> > > >Chuck
> > > >
> > > > > -----Original Message-----
> > > > > From: sam s [mailto:[EMAIL PROTECTED]
> > > > > Sent: Wednesday, October 13, 2004 12:55 PM
> > > > > To: [EMAIL PROTECTED]
> > > > > Subject: Filtering Results?
> > > > >
> > > > > Hi,
> > > > > I want to do filtering on matched results of a query.
> > > > > For example
> > > > > 1. age > 18
> > > > > 2. age < 18
> > > > > 3. age > 5 and age < 18
> > > > > 4. birthdate = [some date]
> > > > > What can be the best approach?
> > > > > How can it be done with range query?
> > > > > Can it be done without range query?
> > > > >
> > > > > Also.
> > > > > Where can I find information meaning of following classes and
how
> >to
> > > >use
> > > > > them?
> > > > > FilteredQuery
> > > > > QueryFilter (I didnt understand much looking at test case of
this)
> > > > > CachingWrapperFilter
> > > > > etc..
> > > > >
> > > > > Thanks in advance
> > > > >
> > > > >
_________________________________________________________________
> > > > > Don't just search. Find. Check out the new MSN Search!
> > > > > http://search.msn.com/
> > > > >
> > > > >
> > > > >
> >---------------------------------------------------------------------
> > > > > To unsubscribe, e-mail:
[EMAIL PROTECTED]
> > > > > For additional commands, e-mail:
> >[EMAIL PROTECTED]
> > > >
> > > >
> > >
>---------------------------------------------------------------------
> > > >To unsubscribe, e-mail:
[EMAIL PROTECTED]
> > > >For additional commands, e-mail:
[EMAIL PROTECTED]
> > > >
> > >
> > > _________________________________________________________________
> > > Don't just search. Find. Check out the new MSN Search!
> > > http://search.msn.com/
> > >
> > >
> > >
---------------------------------------------------------------------
> > > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > > For additional commands, e-mail:
[EMAIL PROTECTED]
> >
> >
> >---------------------------------------------------------------------
> >To unsubscribe, e-mail: [EMAIL PROTECTED]
> >For additional commands, e-mail: [EMAIL PROTECTED]
> >
> 
> _________________________________________________________________
> Don't just search. Find. Check out the new MSN Search!
> http://search.msn.com/
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to