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.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
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"