在solr查询中使用不相等或丢失

发布于 2025-01-19 08:56:56 字数 250 浏览 2 评论 0 原文

寻找一种将以下表达式转换为solr查询的方法。

isnull(field)或field!= 1

我尝试了几件事,

field:1或-field:*

- ( - 字段:1和field:1 and field: *)

( - 字段:1或(*:* - field:*))

Looking for a way to convert following expression to solr query.

ISNULL(field) OR field != 1

I have tried several things,

-field:1 OR -field:*

-(-field:1 AND field:*)

(-field:1 OR (*:* -field:*))

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

相思碎 2025-01-26 08:56:56

Solr 标准查询解析器不支持在字段中搜索空/空值。在这种情况下,需要否定过滤器(排除字段中具有任何值的文档),以便查询保持有效。

但是,使用 范围查询在否定子查询中使用通配符时,最好防止出现不一致的行为。

因此 ISNULL(field) 变为 -field:[* TO *]

另外,在同一个 fq 参数中应用过滤器和否定过滤器时,需要添加 *:* 并确保第一个 - 运算符仅适用于使用括号的第一个过滤器,否则 OR 将无法正确应用。因此,如果要将此过滤器与其他过滤器组合,请确保过滤器与结果集相交(假设过滤器应适用于所有文档):

fq=(-field:[* TO *]) OR (*:* AND -field:<val>)

请注意,这相当于:

fq=-(field:[* TO *] AND field:<val>)

这意味着您只需要该部分(只要 < val> 不为 null,即与 1 不同的值匹配包括 null/空值):

fq=-field:<val>

Solr Standard Query Parser does not support searching a field for empty/null value. In this situation the filter needs to be negated (exluding documents having any value in the field) so that the query remains valid.

However, using a range query is preferred to prevent inconsitent behaviors when using wildcard within negative subqueries.

So ISNULL(field) becomes -field:[* TO *]

Also, when applying a filter and a negated filter in the same fq param, you need to add *:* on the latter and ensure the first - operator applies to only the first filter using parentheses, otherwise the OR won't apply properly, . So if this filter is to be combined with others, ensure the filter intersects the resultset (assuming that filter should apply to all documents) :

fq=(-field:[* TO *]) OR (*:* AND -field:<val>)

Note this is equivalent to :

fq=-(field:[* TO *] AND field:<val>)

Which means you only need that part (as long as <val> is not null, ie. matches with a value different than 1 includes null/empty values) :

fq=-field:<val>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文