问题描述
我有一个网站,我刚刚为其编写了出色的搜索功能.我只是意识到我的数据库中有一些带有重音符号的单词.因此,当有人输入要搜索的单词时,当然没有重音符号,他们找不到要查找的内容.
I've got a website for which I just wrote a great search function. I just realized that I have some words in my db with accent marks. So when somebody types in the word to search for, without the accent mark of course, they don't find what they are looking for.
到目前为止,大多数搜索功能已经解决了该问题;他们是如何做到的呢?必须有一些聪明的把戏.我的大多数查询都使用mysql的MATCH功能,但其中之一使用LIKE.
most search functions have solved this problem by now; how do they do it? There must be some clever trick to it. Most of my queries use mysql's MATCH feature but one of them uses LIKE.
推荐答案
您需要设置特定的排序规则,以便MySQL知道应该认为哪些字符是等效的.是否将带有变音标记的字母视为与不带变音符号的字母相同,还是取决于其他字符序列,取决于语言,但是请尝试以utf8_general_ci作为忽略重音的起点(假设您使用的是UTF-8字符集,应该是真的.)
You need to set a particular collation on your schema so that MySQL knows which characters are supposed to be equivalent. Whether a letter with a diacritical mark is considered the same as one without or some other sequence of characters is language-dependent, but try utf8_general_ci as a starting point for ignoring accents (assuming you're using a UTF-8 character set, which you should be really).
尝试在所有字符串上使用相同的排序规则,以便可以进行合并和比较,而无需进行昂贵的索引破坏转换.
Try to use the same collation on all your strings, so that they can be joined and compared without expensive, index-breaking conversions.
这篇关于匹配带有重音符号,变音符号等的单词.mysql/php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!