2

我找到了很多关于排序规则和口音不敏感搜索的答案,阅读了 1000 篇关于这个问题的帖子和文章,但没有找到答案。

有人知道如何强制 mysql 搜索对所有波兰语字符不敏感的重音吗?也许有人得到了那个(Debian)的编译整理文件?

请注意:

  • 将排序规则设置为utf8_general_ci没有帮助。它不支持Ł正确。但它确实破坏了搜索顺序。
  • 将排序规则设置为utf8_unicode_ci没有帮助。和上面一样。
  • 无法编辑排序规则文件,因为它是多字节编码。并且必须编译多字节字符集。
  • 将所有不受支持的字母替换为受支持的字母不是解决方案。

我真的不明白为什么 MySQL 工作人员不把它当作一个错误来威胁。很明显,确实如此,而且已经存在了很长时间。从 4.xx 开始,他们做了正确的Ś字母......那为什么不Ł呢?!

我发现了一些对这个 MySQL 功能的引用,但没有关于如何使用它的信息。我真的不明白那里写的是什么以及它是否可以帮助我。

测试:

mysql> show full columns from test;
+-------+--------------+----------------+------+-----+---------+-------+---------------------------------+---------+
| Field | Type         | Collation      | Null | Key | Default | Extra | Privileges                      | Comment |
+-------+--------------+----------------+------+-----+---------+-------+---------------------------------+---------+
| str   | varchar(255) | utf8_polish_ci | YES  |     | NULL    |       | select,insert,update,references |         |
+-------+--------------+----------------+------+-----+---------+-------+---------------------------------+---------+

mysql> insert into test values('Łomża');

...

mysql> select str from test where str like '%Łomża%'\G
*************************** 1. row ***************************
str: Łomża

mysql> select str from test where str like '%Łomza%'\G
Empty set (0.00 sec)

--

mysql> select str from test where str like '%Łomza%' collate utf8_general_ci\G
*************************** 1. row ***************************
str: Łomża

mysql> select str from test where str like '%Lomza%' collate utf8_general_ci\G
Empty set (0.00 sec)

--

mysql> select str from test where str like '%Łomza%' collate utf8_unicode_ci\G
*************************** 1. row ***************************
str: Łomża

mysql> select str from test where str like '%Lomza%' collate utf8_unicode_ci\G
Empty set (0.00 sec)
4

2 回答 2

3

我刚开始使用 MySql,“波兰语”问题的答案是整理utf8_unicode_520_ci(或utf8mb4_unicode_520_ci)哪里l=ł=L=Ł- 其他口音(不仅是波兰口音)也是如此。

没有 char 转换,没有 ascii 列,什么都没有……经过多年在 Sqlite 中搜索 ł/Ł 解决方案。

于 2018-08-18T22:46:09.190 回答
0

我建议创建另一列用于在您的数据库中进行搜索,例如“str_search”。在数据库中向“str_search”插入字符串时,在 PHP 中创建并使用一个函数,如下所示:

 function convertPolishChars($phrase)
 {
    $phrase = str_replace("ą", "a", $phrase);
    $phrase = str_replace("Ą", "A", $phrase);

    $phrase = str_replace("ć", "c", $phrase);
    $phrase = str_replace("Ć", "C", $phrase);

    $phrase = str_replace("ę", "e", $phrase);
    $phrase = str_replace("Ę", "E", $phrase);

    $phrase = str_replace("ł", "l", $phrase);
    $phrase = str_replace("Ł", "L", $phrase);

    $phrase = str_replace("ń", "n", $phrase);
    $phrase = str_replace("Ń", "N", $phrase);

    $phrase = str_replace("ó", "o", $phrase);
    $phrase = str_replace("Ó", "O", $phrase);

    $phrase = str_replace("ś", "s", $phrase);
    $phrase = str_replace("Ś", "S", $phrase);

    $phrase = str_replace("ź", "z", $phrase);
    $phrase = str_replace("Ź", "Z", $phrase);

    $phrase = str_replace("ż", "z", $phrase);
    $phrase = str_replace("Ż", "Z", $phrase);

    return $phrase;
 }

"INSERT INTO test (str, str_search) VALUES ('Łomża', '" . convertPolishChars('Łomża') . "')"

在编写 SQL 查询时,编写如下内容:

"SELECT str FROM test WHERE str_search like '%" . convertPolishChars('Łomża') . "%'"

这种方法将更快地执行您的查询字符串,而不是在 SQL 语句中进行任何转换。

确保索引您的“str_search”列。

对于较大的数据库,我建议使用MATCH AGAINST进行FULLTEXT搜索。 http://dev.mysql.com/doc/refman/5.0/en/fulltext-search.html

于 2014-12-16T16:13:49.480 回答