An alternative to Lucene's NumberTools, is Solr's NumberUtils, which is more space efficient for indexing numbers, but not as pretty to look at
http://lucene.apache.org/solr/api/org/apache/solr/util/NumberUtils.html Dan Hardiker 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: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]