匹配带有重音符号,变音符号等的单词.mysql/php [英] matching against words with accent marks, umlauts, etc. mysql/php

查看:124
本文介绍了匹配带有重音符号,变音符号等的单词.mysql/php的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网站,我刚刚为其编写了出色的搜索功能.我只是意识到我的数据库中有一些带有重音符号的单词.因此,当有人输入要搜索的单词时,当然没有重音符号,他们找不到要查找的内容.

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.

推荐答案

您需要设置特定的

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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆