Loading...
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…”







| www.flickr.com |
Leave a reply