如何用SQLite的FTS3实现模糊搜索?

TWi*_*Rob 11 sqlite search android full-text-search fts3

我已经基于官方Android文档集成了搜索,我正在使用以下SQLite架构和查询:

CREATE VIRTUAL TABLE Search USING FTS3 (
    _id,
    name,
    location
);

select * from Search where name MATCH ?
-- where ? is the user typed exact "query"
-- or if it doesn't have spaces or stars I append a star to search prefix: "query*"
Run Code Online (Sandbox Code Playgroud)

我想知道如何扩展它?允许以下内容:

说我有一些名为的物品:

  • 我喜欢的物品
  • 我的秘密物品
  • 项目#1
  • 你喜欢的物品

当用户blah在搜索框中输入内容时,搜索结果会显示:

  • my
    • 喜欢的物品
    • 我的秘密物品
  • mfi
    • 中号 Ÿ ˚F ancy TEM
  • fan item,fanit,fit
    • 我的粉丝 CY EM
    • 你的 CY EM
  • it,item,im,itm
    • 我的幻想中号
    • 我的秘密中号
    • #1
    • 你看中的中号

结果应根据匹配的好坏进行排名,例如,如果字母距离较远,则应排名低于完全匹配,例如mfi:"我喜欢的项目"应排在最后,"MFI thingy"应排在第一位(如果有这样的项目).

注意:我的min SDK是API级别10,这意味着它必须使用SQLite 3.6.22.

类似的功能主要在IDE中找到:

CL.*_*CL. 4

SQLite 的 FTS 只允许搜索整个单词或单词前缀。

没有像这样的模糊搜索的内置功能。(Android 数据库 API 不允许您添加自定义虚拟表实现。)

  • 有什么替代方案吗? (2认同)