开发者

ilike search working irregularly with characters "ÅÄÖ"

Alright, so I've got a pretty weird error.

Say I have the string "Ön Åsa Äpple föll ner i sjön"

query      |result
Ön         |Found
ÖN         |Found
ön         |Found
<same pattern works with Åsa and Äpple as well>

föll       |Found
Föll       |Found
FÖLL       |Not found

This doesn't make any sense to me. Clearly searching with capital ÅÄÖ works, but for some reason not when the ÅÄÖ-character is not the first letter of a word?

I have a Rails application and a MYSQL database. This is the corresponding code:

dataset = DB[category_class.table_name.to_sym]
    dataset = dataset.where(:headline.ilike("%" + headline + "%")) if headline.present?

I'd be very grateful for any comm开发者_JS百科ents or answers that leads me in the right direction to solving this problem.

Regards, Emil


This is probably something to do with the way the utf8_unicode_ci collation compares strings. A collation is a collection of rules that determine when two strings are considered "the same", and when they are not; it also determines the order in which strings are sorted.

To see the collations for the utf8 character set, issue SHOW COLLATION LIKE 'utf8'. You will see that there are a variety of language-specific collations. These don't limit the values you can store in the column* but rather impose string comparison rules tailored towards text that is expected to be primarily in a specific language. Alternatively, you can use the utf8_general_ci collation which ignores accents entirely.

* Although if unique keys are involved, they might change whether one value is considered a duplicate of another or not.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜