滚动到最后跳过解释.
背景
在我的Android应用程序中,我想使用非英语Unicode文本字符串来搜索存储在SQLite数据库中的文本文档/字段中的匹配项.我已经学会了(所以我想)我需要做的是实现一个Full Text Search with fts3/fts4,这就是我过去几天一直在学习的东西. Android支持FTS,如文档Storing and Searching for Data和博客文章Android Quick Tip: Using SQLite FTS Tables所示.
问题
一切都很好看,但后来我读到了2012年3月的博客文章The sorry state of SQLite full text search on Android
The first step when building a full text search index is to break down
the textual content into words, aka tokens. Those tokens are then
entered into a special index which lets SQLite perform very fast
searches based on a token (or a set of tokens).SQLite has two built-in 07004, and they both only consider tokens
consisting of US ASCII characters. All other, non-US ASCII characters
are considered whitespace.
之后我还在@CL.找到了this StackOverflow answer(根据标签和声誉,他们似乎是SQLite的专家)回答了一个关于匹配越南字母与不同变音符号的问题:
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.
This 2011 SO answer似乎证实Android不支持两个基本的简单和移植者之外的标记器.
这是2015年.这种情况有没有更新?我需要使用我的应用程序支持所有人的全文搜索,而不仅仅是拥有新手机的人(即使最新的Android版本现在支持它).
可能部分解决方案
我发现很难相信FTS根本不适用于Unicode.简单标记器的documentation说
A term is a contiguous sequence of eligible characters, where eligible
characters are all alphanumeric characters and all characters with
Unicode codepoint values greater than or equal to 128. All other
characters are discarded when splitting a document into terms. Their
only contribution is to separate adjacent terms. (emphasis added)
这让我希望Android中仍然可以支持一些基本的Unicode功能,即使不支持大写和变音符号(以及具有不同Unicode代码点的各种其他等效字母形式).
我的主要问题
如果我只使用由空格分隔的文字Unicode字符串标记,我可以在Android中使用带有非英语Unicode文本(代码点> 128)的SQLite FTS吗? (也就是说,我正在搜索文本中出现的确切字符串.)
更新
> unicode61 tokenizer在SQLite版本3.7.13中可用.此标记器支持“完全unicode case折叠”和“识别unicode空格和标点字符”. Android Lollipop (API 20+) uses SQLite 3.8.
解决方法:
Unicode字符的处理方式与“普通”字母类似,因此您可以在FTS数据和搜索字词中使用它们. (前缀搜索也应该有用.)
问题是Unicode字符没有规范化,即所有字符都被视为字母(即使它们实际上是标点符号( – †),或其他非字母字符(☺♫)),并且大写/小写不合并,并没有删除变音符号.
如果要正确处理这些情况,则必须在将文档插入数据库之前以及使用搜索术语之前手动执行这些规范化.
原文地址:https://codeday.me/bug/20190609/1205240.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。