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…”
i was using lucene for indexing my textual content, when i removed all of my index files, i have been introduced with a strange “LuceneIndexAccessException(The index is locked)” exception. though my whole directory was empty. it was not suppose to show this kind of exception.
anyway, later i found there is a property called “resolveLock” which is required to enable auto lock resolve option.
hope this will help to those who face such problem.
< bean id="indexFactory"
class="org.springmodules.lucene.index.support.SimpleIndexFactoryBean" >
< property name="directory" ref="fsDirectory"/ >
< property name="create" value="true"/ >
< property name="analyzer" ref="analyzer"/ >
< property name="resolveLock" value="true"/ >
< /bean >
best wishes,







| www.flickr.com |
Leave a reply