Sunspot/Solr queries ending with logical operators AND/OR/NOT result in error

主宰稳场 提交于 2019-12-05 21:27:49

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