MySQL变音符号不敏感搜索(西班牙口音) [英] MySQL diacritic insensitive search (spanish accents)
问题描述
我有一个 MySQL 数据库,其中包含西班牙语 (áéíóú) 重音的单词.我想知道是否有任何方法可以进行变音符号不敏感搜索.例如,如果我搜索lapiz"(没有重音),我想从我的数据库中获得包含lápiz"这个词的结果.我目前做查询的方式如下:
I have a MySQL database with words containing accents in Spanish (áéíóú). I'd like to know if there's any way to do a diacritic insensitive search. For instance, if I search for "lapiz" (without accent), i'd like to get results containing the word "lápiz" from my db. The way I'm currently doing the query is as follows:
$result = mysql_query("SELECT * FROM $lookuptable WHERE disabled = '0' AND name LIKE '%$q%' OR productCode LIKE '%$q%' LIMIT $sugglimit");
这是一个在线商店,所以我不知道人们会搜索什么......lapiz"只是一个例子.
This is for an online store, so I don't know what people will be searching for... "lapiz" is just and example.
替代文字 http://www.freeimagehosting.net/uploads/0e7c2ae7d5.png
谢谢!
推荐答案
字符集 &排序规则,不是我的最爱,但它们确实有效:
Character sets & collations, not my favorites, but they DO work:
mysql> SET NAMES latin1;
mysql> SELECT 'lápiz' LIKE 'lapiz';
+-----------------------+
| 'lápiz' LIKE 'lapiz' |
+-----------------------+
| 0 |
+-----------------------+
1 row in set (0.01 sec)
mysql> SET NAMES utf8;
mysql> SELECT 'lápiz' LIKE 'lapiz';
+-----------------------+
| 'lápiz' LIKE 'lapiz' |
+-----------------------+
| 1 |
+-----------------------+
mysql> SET NAMES latin1;
mysql> SELECT _utf8'lápiz' LIKE _utf8'lapiz' ;
+---------------------------------+
| _utf8'lápiz' LIKE _utf8'lapiz' |
+---------------------------------+
| 1 |
+---------------------------------+
手册中值得一读的好章节:字符集支持一个>
A nice chapter to read in the manual:Character Set Support
这篇关于MySQL变音符号不敏感搜索(西班牙口音)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!