Lucene numeric range search with LUKE

与世无争的帅哥 提交于 2019-12-03 20:23:47

If the fields are indexed as NumericField you must use "Use XML Query Parser" option in query parser tab and the 3.5 version of Luke:

https://code.google.com/p/luke/downloads/detail?name=lukeall-3.5.0.jar&can=2&q=

An example of query with a string and numeric field is:

<BooleanQuery>
<Clause fieldName="colour" occurs="must">
    <TermQuery>rojo</TermQuery>
</Clause>
<Clause fieldName="price" occurs="must">
    <NumericRangeQuery type="int" lowerTerm="4000" upperTerm="5000" />
</Clause>
</BooleanQuery>

The solution I used for this was that the values inputted for price needed to be added to the index in padded form. Then I would just query the new padded value which works great. Therefore the new values in the index were:

060000
078500
105000

This solution was tied into an Examine search issue for Umbraco so there is a thread on the Forum of how to implement a numeric based range search if anyone requires this it is located here with a walk through end to end.

Umbraco Forum Thread

  1. Zero padding won't come into this particular query since all the numbers you've shown have the same number of digits
  2. The range query you've shown has too many zeros on the second part of the range
  3. So the query for the data you've shown would be price:[10500 TO 78500]

Hope this helps,

I assume these fields are indexed as NumericFields. The problem with them is that Lucene/Luke does not know how to parse numeric queries automatically. You need to override Lucene's QueryParser and provide your own logic how these numbers should be interpreted.

As far as I know, Luke allows sticking in your custom parser, it just need to be present in the CLASSPATH.

Have a look at this thread on Lucene mailing list:

http://mail-archives.apache.org/mod_mbox/lucene-java-user/201102.mbox/%3CAANLkTi=XUpyw09tcbjuTzNRpMJa730Cq-6_1agMAjYz6@mail.gmail.com%3E

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!