简体   繁体   English

全文搜索mysql中的撇号

[英]Apostrophe in FULL TEXT SEARCH mysql

When I searched for citroen in search page like that I get result but if I search blackn roll I dont get result because it's written like black'n roll in the table. 当我在这样的搜索页面中搜索雪铁龙时,会得到结果,但是如果我搜索blackn roll,则不会得到结果,因为它在表中写成black'n roll。 Some user may also wanna search blackn roll but doesnt get result. 某些用户可能还想搜索“变黑”,但没有得到结果。 How can I fix it? 我该如何解决? And also rows like v-hr and speacial characters like "&/(). I want the mysql to ignore them. 还有像v-hr这样的行和像“&/()这样的特殊字符。我希望mysql忽略它们。

$sql = "SELECT * FROM arac 
        INNER JOIN suv_marka ON arac.marka = suv_marka.id 
        WHERE match(suv_marka.marka) against('citroen')";

If you know the characters (to be replaced) already then, you can use MySQL's REPLACE function to replace them with % and perform LIKE comparison, eg: 如果您已经知道要替换的字符,则可以使用MySQL的REPLACE函数将它们替换为%并执行LIKE比较,例如:

create table test(value varchar(100));
insert into test values ('black''n roll');


SELECT value 
FROM test 
WHERE 'blackn roll' LIKE CONCAT('%', REPLACE(value, '''', '%'), '%');

You can replace 'blackn roll' with your input string and use nested REPLACE functions if you need to replace more than one character. 您可以使用输入字符串替换“ blackn roll”,如果需要替换多个字符,则可以使用嵌套的REPLACE函数。

The back-slash is MySQL's escape character. 反斜杠是MySQL的转义字符。 You can try the following... Full text indexing gets a little weird because of word terminators. 您可以尝试以下操作...全文索引由于单词终止符而有些奇怪。

$sql = "SELECT * FROM arac 
        INNER JOIN suv_marka ON arac.marka = suv_marka.id 
        WHERE match(suv_marka.marka) against ('black\'n roll' IN BOOLEAN MODE);"

If that doesn't work, then try looking for the words individually. 如果这样不起作用,请尝试逐个查找单词。 Word length is also a factor, small words (less than 4 characters by default) are not indexed. 单词长度也是一个因素,小单词(默认情况下少于4个字符)不会被索引。

$sql = "SELECT * FROM arac 
        INNER JOIN suv_marka ON arac.marka = suv_marka.id 
        WHERE match(suv_marka.marka) against ('black' + 'roll' IN BOOLEAN MODE);"

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

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