使用 LUKE 进行 Lucene 数字范围搜索
我有许多数字 Lucene 索引字段:
60000
78500
105000
如果我使用 LUKE 查询 78500,如下所示:
price:78500
它返回正确的记录,但是如果我尝试将所有三个记录作为范围返回,我不会得到任何结果。
price:[60000 TO 105000]
我意识到这是由于填充造成的,因为 Lucene 将数字视为字符串,但我只是想知道应该将什么放入 LUKE 中以返回三个记录。
非常感谢您的帮助。
I have a number of numeric Lucene indexed fields:
60000
78500
105000
If I use LUKE to query for 78500 as follows:
price:78500
It returns the correct record, however if I try to return all three record as a range I get no results.
price:[60000 TO 105000]
I realise this is due to padding as numbers are treated strings by Lucene however I just wish to know what I should be putting into LUKE to return the three records.
Many thanks for any help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果字段被索引为 NumericField,则必须在查询解析器选项卡和 3.5 版本的 Luke 中使用“使用 XML 查询解析器”选项:
https://code.google.com/p/luke/downloads/detail?name=lukeall-3.5.0.jar&can=2& ;q=
使用字符串和数字字段的查询示例如下:
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:
我为此使用的解决方案是,输入的价格值需要以填充形式添加到索引中。然后我会查询新的填充值,效果很好。因此,索引中的新值是:
此解决方案与 Umbraco 的“检查”搜索问题相关联,因此论坛上有一个关于如何实现基于数字的范围搜索的主题(如果有人需要的话),它位于此处,并带有一个演练结束结束。
Umbraco 论坛主题
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:
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
price:[10500 TO 78500]
希望这会有所帮助,
price:[10500 TO 78500]
Hope this helps,
我假设这些字段被索引为 NumericField。它们的问题是 Lucene/Luke 不知道如何自动解析数字查询。您需要重写 Lucene 的 QueryParser 并提供您自己的逻辑来解释这些数字。
据我所知,Luke 允许使用自定义解析器,它只需要出现在 CLASSPATH 中即可。
查看 Lucene 邮件列表上的此线程:
http://mail-archives.apache.org/mod_mbox/lucene-java-user/201102.mbox/%
I assume these fields are indexed as
NumericField
s. The problem with them is that Lucene/Luke does not know how to parse numeric queries automatically. You need to override Lucene'sQueryParser
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/%[email protected]%3E