我有一个搜索古希腊单词的功能 ( Wearch.nl )。
旧的希腊语单词有 mutch 重音,ῦ 与 ὐ 不同,但我希望如果您键入“u”,您会得到 ῦ 和 ὐ(以及其他 5 个变体)的结果。我正在使用 MySQL 的 LIKE 函数来获取结果。
我可以搜索所有这些,但我希望它可以更短更快。
最佳答案
如果您能够更改列(或表)的字符集,则将其设置为 utf8_general_ci
( link to manual ):
ALTER TABLE tbl_name CONVERT TO CHARACTER SET utf8_general_ci;
使用此字符集(不区分大小写,如 _ci
所示),重音字符具有相同的权重(用于 collation 的值),因此它们在与每个字符比较时返回 true其他(link to manual):
Non-UCA collations have a one-to-one mapping from character code to weight. In MySQL, such collations are case insensitive and accent insensitive. utf8_general_ci is an example: 'a', 'A', 'À', and 'á' each have different character codes but all have a weight of 0x0041 and compare as equal.
mysql> SET NAMES 'utf8' COLLATE 'utf8_general_ci';
Query OK, 0 rows affected (0.00 sec)
mysql> SELECT 'a' = 'A', 'a' = 'À', 'a' = 'á';
+-----------+-----------+-----------+
| 'a' = 'A' | 'a' = 'À' | 'a' = 'á' |
+-----------+-----------+-----------+
| 1 | 1 | 1 |
+-----------+-----------+-----------+
1 row in set (0.06 sec)
或者,或者如果您不能以这种方式更改数据库配置,您可以编写一个函数来将重音字符替换为非重音字符(即 é
-> e
) 并将其写入专用搜索字段(建议使用 full-text search 字段)。对该字段执行搜索并将重音字段返回给应用程序。
关于php - MySQL 中的希腊字符搜索功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6397973/