开发者

MySQL search Chinese characters

Let's say I have a row:

一天吃一個蘋果

Someone enters as a query:

天蘋

Should I break up the characters in the开发者_开发技巧 query, and individually perform a LIKE % % match on each character against the row, or is there any easier way to get a row that contains one of the two characters? FULLTEXT won't work with CJK characters.

Thanks!


Supposed you are searching for all query characters in a string and care about the character order.

First split the user query. Say 天蘋 to and .

Then construct a SQL query with LIKE and %, for example, WHERE x LIKE '%天%蘋%'.


It seems we need a vocabulary to perform correct chinese search. They do not have spaces yet they still have words. For example, we've got something like "ieatpear" on input. We should split it into any possible amount of words of 1-4 letters. i ie iea ieat e ea eat eatp a at atp atpe t tp tpe tpea p pe pea pear e ea ear a ar r

Than our algorhythm finds real words - I eat pear ear. On the next step we can exclude ear for it's already in pear and perform search within pre-splitted vocabulary.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜