SQLite full-text search unicode in android

走远了吗. 提交于 2019-12-12 17:07:05

问题


I am creating a table in SQLite using fts(3 or 4)

CREATE VIRTUAL TABLE Demo1 USING fts3(content TEXT);

insert into Demo1 values('Hồ Thanh Long'),('Nguyễn Văn A')

When search:

select * from Demo1 where content  Match 'Hồ' 

Then result is:

'Hồ Thanh Long'

When search:

select * from Demo1 where content  Match 'Ho' 

Then no result.

Help me!


回答1:


You must create the FTS table with a tokenizer that can handle Unicode characters, i.e., ICU or UNICODE61.

Please note that these tokenizers might not be available on all Android versions, and that the Android API does not expose any functions for adding user-defined tokenizers.




回答2:


The default "simple" tokenizer for android supports unicode:

where eligible characters are all alphanumeric characters and all characters with Unicode codepoint values greater than or equal to 128.

It just doesn't do anything else. I'm not sure even the Unicode tokenizers would do the mapping you require. (i.e. recognize 'Hồ' as both 'Hồ' and 'Ho' when queried.)

Indeed, the demo recognized 'Hồ' when you queried it; it just didn't return it when you queried 'Ho' because it didn't recognize them as equivalents. If you are working with a limited set of supported Unicode characters, you could implement your own mapping, and save the "plain ASCII text" in a separate column to search on separately.



来源:https://stackoverflow.com/questions/17396404/sqlite-full-text-search-unicode-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!