Ruby on Rails:根据数据库排序规则比较两个字符串
我有一个单词列表,想查找数据库中已经存在的单词。
我决定使用“SELECT word
FROM table
WHERE word
IN(array_of_words)”,而不是进行数十个 SQL 查询,然后循环遍历结果。
问题是数据库排序规则。
http://www.collation-charts.org/mysql60/mysql604.utf8_general_ci .european.html
有很多不同的字符,MySQL 将其视为相同。但是,在 Ruby 代码中 string1 不等于 string2。
例如:如果单词是“šuo”,数据库也可能返回“suo”,如果找到的话(并且没问题),但是,当我想检查是否找到“šuo”的内容时,Ruby,当然,返回 false (šuo != suo)。
那么,有没有办法在 Ruby 中根据相同的排序规则来比较两个字符串呢?
I have a list of words and want to find which ones already exist in the database.
Instead of making tens of SQL queries, I decided to use "SELECT word
FROM table
WHERE word
IN(array_of_words)" and then loop through the result.
The problem is database collation.
http://www.collation-charts.org/mysql60/mysql604.utf8_general_ci.european.html
There are many different characters, which MySQL treats as the same. However, in Ruby code string1 would not be equal to string2.
For example: if the word is "šuo", database might also return "suo", if it's found (and it's ok), but, when I want to check, if something by "šuo" is found, Ruby, of course, returns false (šuo != suo).
So, is there any way to compare two strings in Ruby in terms of the same collation?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我已经使用 iconv 来完成类似的事情:
希望有帮助!
祖宾
I've used iconv like this for something similar:
Hope that helps!
Zubin