本文介绍了在mysql中选择相似的值(某些东西,söméthińg,某些东西,某些东西应该是相同的)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个标签系统,我需要检索相似的标签,因此,当用户输入某物"或某物"或某物"或某物"时,他将获得全部信息表中匹配的行.

I'm building a tagging system and I need to retrieve similar tags, so when a user would punch in "some thing" or "somé thing" or "söme thing" or "some¤thing" etc he would get all the matching rows in the table.

如果我在田间使用utf8_generalutf8_unicode,那将是小菜一碟.我可以

If I were using utf8_general or utf8_unicode on the field, it would be a piece o' cake. I could just

SELECT * FROM tags WHERE tag LIKE 'some thing'

但是,我需要在该表中使用utf8_bin.那么,我该怎么办?我不是一个很大的mysql专家.我想我应该使用CAST()或CONVERT(),但是我不确定如何使用.

but alas, I need to use utf8_bin in that table. So, what do I do? I'm not a very big mysql expert. I think I should be using CAST() or CONVERT() but I'm not sure how.

第二部分,获取某物,某物,某物等是另一个问题,但我想我可以自己使用正则表达式来解决它

The second part, getting the some-thing, some*thing, some&thing etc, is another issue, but I think I can solve it on my own with Regular Expressions

解决方案我认为弄乱所有这些转换和正则表达式可能不是最好的方法.相反,我将使用框架的方法并生成给定标记的URL名称",并将其存储在同一数据库行中.

THE SOLUTIONI thought that messing around with all this converting and regexping might not be the best way. Instead, I will use my framework's methods and generate a URL "name" of given tag and store it on the same db row.

推荐答案

是的,转换为:-


mysql> select convert( "söme thing" using utf8) = 
convert( "some thing" using utf8);
+------------------------------------------------------------------------+
| convert( "söme thing" using utf8) = convert( "some thing" using utf8)  |
+------------------------------------------------------------------------+
|                                                                      1 |
+------------------------------------------------------------------------+

但是我认为使用utf8_bin没有好处

But I think is no benefits to use utf8_bin

在处理标签搜索时,您可以考虑存储

When handling search of tag, you can consider to store

  • 干净版本(某些)
  • 用于将söme和其他变体映射到干净版本的附加表
  • 当用户搜索söme时,可以查找söme= some

这篇关于在mysql中选择相似的值(某些东西,söméthińg,某些东西,某些东西应该是相同的)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-21 20:15