使用表情符号不区分大小写地查找值

3

我有一个包含varchar值的表格,需要存储带有表情符号的文本值:

CREATE TABLE `my_table` (
  `id` bigint(11) NOT NULL AUTO_INCREMENT,
  `value` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `value_idx` (`value`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci

现在我需要在这个表上进行选择,以查找以前缀开头的所有值。选择必须是不区分大小写的,并且必须匹配表情符号。到目前为止,我找到了4个选项,它们都存在权衡:

  1. I can use utf8mb4_unicode_ci collation and do selects like

    select * from my_table where value like 'prefix%'

    It will wind all values starting with prefix ignoring its characters case, but will not find anything if prefix contains emojis

  2. I can set collection to utf8mb4_bin and my selects will find values if prefix contains emojis, but will be case sensitive

  3. I can do

    select * from my_table where LOWER(value) like 'prefix%'

    and it will work case insensitively and with emojis, but will not use index

  4. And finally I can save all values in lower case and use utf8mb4_bin collation, but saving in lower case is also the trade off

有没有一种解决方案,可以让我忽略前缀的大小写并允许前缀中有表情符号来进行"like"查询?
更新:我不是在存储表情符号时遇到问题,而是在使用"like"查询时保持不区分大小写的排序顺序时找不到它们。

可能是在MySQL中存储Android表情符号的重复问题。 - Wasiq Muhammad
1
绝对不是,那个问题涉及储存表情符号的问题。我没有遇到这样的问题,因为我使用 utf8mb4,它能够储存 4 字节 Unicode 字符。 - Dmitry Shohov
1个回答

1
解决方案是使用MySQL 5.6+,并使用utf8mb4_unicode_520_ci排序规则,该规则不将所有4字节字符视为相等。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接