lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Erick Erickson" <erickerick...@gmail.com>
Subject Re: Numerical Range Query
Date Mon, 12 May 2008 18:15:51 GMT
Yep, lucene works with strings, not numbers so the fact that you're
not getting what you expect is expected <G>.

Although I'm a bit puzzled by what you're actually getting back.
You might try using Luke to look at your index to see what's
there.

See the NumberTools class for some help here.......

BTW, at least in Lucene 2.1, the preferred way to go about this
would be ConstantScoreRangeQuery...

Best
Erick

On Mon, May 12, 2008 at 1:39 PM, Dan Hardiker <dhardiker@adaptavist.com>
wrote:

> Hi,
>
> I've got an application which stores ratings for content in a Lucene
> index. It works a treat for the most part, apart from the use-case I have
> for being able to filter out ratings that have less than a given number of
> rates. It kinda works, but seems to use Alpha ranging rather than Numeric
> ranging.
>
> Here is the Java code I am using:
>
> luceneQuery.add( new RangeQuery( new Term(RateUtils.SF_FILTERED_CNT,
> minRatesString), null, true), BooleanClause.Occur.MUST );
>
> For context:
>
> * luceneQuery is a org.apache.lucene.search.BooleanQuery
> * RateUtils.SF_FILTERED_CNT is the String containing the appropriate field
> name "rating-filtered-count"
> * minRatesString is an integer as a String
>
> Here is where the field is added into the index:
>
> document.add( new Field(RateUtils.SF_FILTERED_CNT, String.valueOf(
> filteredCount ), Field.Store.YES, Field.Index.UN_TOKENIZED) );
>
> For context:
>
> * document is a org.apache.lucene.document.Document
> * filteredCount is an int (counting the number of rates that have
> occurred)
>
> Unfortunately it doesn't work quite as I expected as if I have 5 documents
> in the index:
>
> # 5 ratings
> # 9 ratings
> # 1 rating
> # 0 ratings
> # 11 ratings
>
> If minRatesString is "5" then only the first document is returned, if it's
> "1" then the 3rd and 5th are returned, if its "6" then none are returned. It
> appears to be filtering alphabetically (starting with the first
> digit/character and matching on that) rather than numerically.
>
> Oddly enough, if I sort on that field ... it works as I expect.
>
> Am I missing something?
>
>
> --
> Dan Hardiker
>
> PS: I've been googling for well over an hour, if I'm not searching with
> the right terms - please advise me! I tried to find a way to search the
> archives specifically, but I could only browse them month by month.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message