简体   繁体   English

在 boolean 模式下带有空字符串的 FULLTEXT INDEX 给出错误“语法错误,意外 $end,期望 FTS_TERM 或 FTS_NUMB 或 '*'”

[英]FULLTEXT INDEX with empty string in boolean mode giving error “syntax error, unexpected $end, expecting FTS_TERM or FTS_NUMB or '*'”

MATCH (a2.name, a2.email) AGAINST ("key*" IN BOOLEAN MODE) //this works
MATCH (a2.name, a2.email) AGAINST ("*" IN BOOLEAN MODE) //doesn’t work 

one option that I have is to write 2 queries on basis of key presence.我有一个选择是根据关键存在编写 2 个查询。 Is there any other option available?还有其他选择吗?

Your application must observe that the user provided an empty string and do something different than blindly throwing it into AGAINST .您的应用程序必须观察到用户提供了一个空字符串,并做一些不同于盲目地将其投入AGAINST的事情。 In this case, leaving the FT clause out of the WHERE might be 'right', but possible 'slow'.在这种情况下,将 FT 子句排除在WHERE之外可能是“正确的”,但可能是“缓慢的”。

Also you may want to avoid 1- and 2-character strings.此外,您可能希望避免使用 1 和 2 字符的字符串。 And strings with punctuation.和带有标点符号的字符串。 And stop words.和停止的话。

Sometimes it is wise to revert to LIKE '%foo%' when the user provides something that you can predict that FT will "do wrong".有时,当用户提供您可以预测 FT 将“做错”的内容时,恢复为LIKE '%foo%'是明智的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM