Sunspot/Solr 查询以逻辑运算符 AND/OR/NOT 结尾会导致错误

发布于 2024-11-05 07:02:19 字数 145 浏览 5 评论 0原文

我注意到以 AND/OR/NOT 示例(“this AND”)等逻辑运算符结尾的查询将导致错误。现在处理这个问题的最佳方法是什么?只是删除或转义所有以其中之一结尾的查询吗?请注意,以这些单词之一开头的查询也会发生这种情况。有时,有效名称以此类词结尾,例如 Oregon OR。

I noticed that queries ending with logical operators like AND/OR/NOT example ('this AND') will result in an error. Now what would be the best way to handle this? Just trim out or escape all the queries ending with one of those? Note that it also happens for queries starting with one of these words. And sometimes, valid names end with such words, like Oregon OR.

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

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

发布评论

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

评论(1

攒一口袋星星 2024-11-12 07:02:19

我相信转义查询中不属于布尔逻辑的任何 AND/OR/NOT 实例将是您最好的选择:

Article.search do
  fulltext 'Oregon OR'
end
# => Throws error along the lines of this:
# RSolr::RequestError: Solr Response: orgapachelucenequeryParserParseException_Cannot_parse_Oregon_OR_Encountered_EOF_at_line_1_column_9_Was_expecting_one_of_____NOT______________________________QUOTED______TERM______PREFIXTERM______WILDTERM__________________NUMBER______TERM____________


Article.search do
  fulltext 'Oregon \OR'
end
# => Returns results with "Oregon OR"

请记住,在双引号字符串中转义 AND/OR/NOT 时,您需要两个反斜杠:

fulltext "Oregon \\OR"

I believe escaping any AND/OR/NOT instances in your query that aren't meant to be boolean logic would be your best bet:

Article.search do
  fulltext 'Oregon OR'
end
# => Throws error along the lines of this:
# RSolr::RequestError: Solr Response: orgapachelucenequeryParserParseException_Cannot_parse_Oregon_OR_Encountered_EOF_at_line_1_column_9_Was_expecting_one_of_____NOT______________________________QUOTED______TERM______PREFIXTERM______WILDTERM__________________NUMBER______TERM____________


Article.search do
  fulltext 'Oregon \OR'
end
# => Returns results with "Oregon OR"

Keep in mind that when escaping AND/OR/NOT in double-quoted strings, you need two backslashes:

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