problem with lucene number range filter

today i was almost stucked with lucene RangeFilter. here is description -

i have used this query – “price:[0 TO 2000]” to find all items which are bellow 2000.
but my search result was also including 12000 any clue ?

good news is i got my solution though it took bit longer to find my actual reason.

the quick answer is i have to use NumberTools.longToString(…) to index my number fields and to perform range search i have to convert my range value using NumberTools.

you can see my code here -
source view

just digging through lucene source code here is what i found -
to perform range query (which is later rewrite to range filter), it tooks lower token for example price: [0 TO 1000] here ’0′ is the lower token. it asks TermInfosReader to return a list of available terms for a specific field (such as price here).

RangeFilter iterate through each suggested term and seek for the token position in a random access segment file.

the problem is, the suggested terms are not sorted. also i didn’t find any way to sort them before filtering out.

though i index my content after sorting them properly. but it didn’t affect any result.

since lucene treats everything as string, and it uses String::compare to determine the range position, i think NumberTools, DateTools are the only way out there.

anyway, i am satisfy with what i got.
best wishes,
“…i do what i love to do…”

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

Gravatar
WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

my tweets

 

April 2008
S S M T W T F
« Feb   May »
 1234
567891011
12131415161718
19202122232425
2627282930  

Flickr Photos

@kamalapur over bridge

@kamalapur station

cox's bazaar trip oct 09

cox's bazaar trip oct 09

cast ur vote!

More Photos
Follow

Get every new post delivered to your Inbox.