matching against words with accent marks, umlauts, etc. mysql/php

爷,独闯天下 提交于 2019-12-18 07:25:12

问题


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.

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.


回答1:


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.



来源:https://stackoverflow.com/questions/1419394/matching-against-words-with-accent-marks-umlauts-etc-mysql-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!