lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael McCandless <luc...@mikemccandless.com>
Subject Re: RangeFilter
Date Wed, 13 Jan 2010 18:29:16 GMT
Actually, as of Lucene 2.9 (if you can upgrade), you should use
NumericField to index numerics and NumericRangeQuery to do range
search/filter -- it all just works -- no more padding.

Mike

On Wed, Jan 13, 2010 at 1:17 PM, Steven A Rowe <sarowe@syr.edu> wrote:
> Hi AlexElba,
>
> The problem is that Lucene only knows how to handle character strings, not numbers.  Lexicographically,
"3" > "10", so you get the expected results (nothing).
>
> The standard thing to do is transform your numbers into strings that sort as you want
them to.  E.g., you can left-pad the "rank" field values with zeroes: "03", "04", ..., "10",
and then create a RangeFilter over "03" .. "10".  You will of course need to left-zero-pad
to at least the maximum character length of the largest rank.
>
> Facilities to handle this problem are available in NumberTools:
>
> <http://lucene.apache.org/java/2_4_0/api/org/apache/lucene/document/NumberTools.html>
>
> (Note that NumberTools converts longs to base-36 fixed-length padded strings.)
>
> More info here:
>
>   <http://wiki.apache.org/lucene-java/SearchNumericalFields>
>
> Steve
>
> On 01/13/2010 at 12:51 PM, AlexElba wrote:
>>
>> Hello,
>>
>> I am currently using lucene 2.4 and have document with 3 fields
>>
>> id
>> name
>> rank
>>
>> and have query and filter when I am trying to use rang filter on rank I
>> am not getting any result back
>>
>> RangeFilter rangeFilter = new RangeFilter("rank", "3", "10", true, true);
>>
>> I have documents which are in this interval
>>
>>
>> Any suggestion what am I doing wrong?
>>
>> Regards
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Mime
View raw message