我有以下针对查询的匹配项,该查询根据搜索短语从数据库表中搜索记录。
SELECT * FROM My_Table WHERE MATCH (catchall) AGAINST ('"horse"' IN BOOLEAN MODE)
该查询工作正常。当搜索短语包含“(”等特殊字符时,它只会跳过这些特殊字符。 如果我搜索“(马)”,它会给出与“马”相同的结果。
SELECT * FROM My_Table WHERE MATCH (catchall) AGAINST ('"(horse)"' IN BOOLEAN MODE)
这是否意味着与查询的匹配不适用于特殊字符,或者我是否遗漏了某些内容。请建议。谢谢。 我尝试从查询中删除 IN BOOLEAN MODE,但它不起作用。
最佳答案
来自 the documentation :
Parentheses group words into subexpressions. Parenthesized groups can be nested.
如果你想将 prenthes 视为“单词字符”,有两种可能性:
If you want to change the set of characters that are considered word characters, you can do so in two ways. Suppose that you want to treat the hyphen character ('-') as a word character. Use either of these methods:
Modify the MySQL source: In myisam/ftdefs.h, see the true_word_char() and misc_word_char() macros. Add '-' to one of those macros and recompile MySQL.
Modify a character set file: This requires no recompilation. The true_word_char() macro uses a “character type” table to distinguish letters and numbers from other characters. . You can edit the contents in one of the character set XML files to specify that '-' is a “letter.” Then use the given character set for your FULLTEXT indexes.
After making the modification, you must rebuild the indexes for each table that contains any FULLTEXT indexes.
第三种方法是根本不使用 MATCH ... AGAINST
而是使用 LIKE
- 但这可能会变得复杂(如果您想使用其他方法)全文搜索运算符,例如 +
/-
)并减慢查询速度。
关于php - Mysql 使用特殊字符搜索匹配查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19263777/