如何编写 solr 查询来检索数字字段值小于指定值的所有记录?
假设我们有一组带有名称和价格的 MP3 播放器。
如何编写正确的 solr 查询来查找具有特定名称且价格低于 100 美元的所有商品?
q = "(名称:(ipod) AND 价格 ???? 100.0)"
Let's assume we have a set of mp3-players with names and prices.
How to write a correct solr query for finding all goods with a certain name and with price less then 100$?
q = "(name:(ipod) AND price ???? 100.0)"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我认为查询解析器不支持
<
运算符。您必须定义 RangeQuery 明确地。然后,您可以使用 布尔查询。更新:显然,我错了。事实上,Solr 的查询解析器比 Lucene 的更智能。这是您的答案:
I don't think the query parser supports
<
operator. You have to define a RangeQuery explicitly. You can then attach a name query to that using a BooleanQuery.Update: Apparently, I was wrong. In fact, Solr's query parser is smarter than Lucene's. Here is your answer: https://lucene.apache.org/solr/guide/8_0/the-standard-query-parser.html#differences-between-lucene-s-classic-query-parser-and-solr-s-standard-query-parser
另请注意,从性能角度来看,您应该为此使用过滤器查询:
also note that performancewise you should use a filter query for this:
据我所知,我不认为 Solr/Lucene 支持大于/小于。它可以以编程方式完成,例如整数和日期(在您的情况下,货币值,因为只需要担心两位小数)。
例如,Lucene 和 Solr 查询解析器本身支持小于或等于 (<=):
这将为您提供您正在寻找的不到 100 美元的数据,前提是数据不涉及一美分的零头。
对于日期和整数之类的东西,或者其他具有显着有限差异的东西,您可以减少(或者在大于的情况下,增加)您想要的值。
编辑:查看 Solr 6.5 版本的文档。它确实包含独家范围支持。
本质上,使用花括号来表示小于。
From my knowledge, I do not believe that Solr/Lucene supports greater/less than. It can be done programmatically for things like integers and dates (and in your case, money values, since there are only two decimal places to worry about).
For example, natively, Lucene and Solr query parsers support less than or equal to (<=):
This would give you the less than 100 dollars that you're looking for, provided the data doesn't involve fractions of a cent.
For things like dates and integers, or other things that have notably finite differences, you can decrement (or in the case of greater than, increment) the value you're going for.
EDIT: Check the documentation for version 6.5 of Solr. It DOES contain exclusive range support.
Essentially, use curly braces to denote less than.