【问题标题】:Android Sqlite FTS3 how to select words that starts with?Android Sqlite FTS3 如何选择以开头的单词?
【发布时间】:2015-02-07 08:15:56
【问题描述】:

例如,如果我有这些记录

单词

AAA

AAB

AAC

呸呸呸

对于一个普通的表,我会使用 sql 之类的

select * from table where word like 'AA%'order by H collate nocase asc

如何改为使用 FTS3 表进行选择? 另外我想知道FTS3在这种查询下是否仍然比普通表有更好的性能?

【问题讨论】:

    标签: android sqlite select fts3


    【解决方案1】:

    如何改为使用 FTS3 表进行选择?

    引用the documentation:

    可以查询 FTS 表中包含指定术语的所有文档(上面描述的简单情况),或包含具有指定前缀的术语的所有文档。正如我们所见,特定术语的查询表达式就是术语本身。用于搜索词条前缀的查询表达式是前缀本身加上一个“*”字符。

    文档还提供了一个示例:

    -- Query for all documents containing a term with the prefix "lin". This will match
    -- all documents that contain "linux", but also those that contain terms "linear",
    --"linker", "linguistic" and so on.
    SELECT * FROM docs WHERE docs MATCH 'lin*';
    

    【讨论】:

    • 希望,从 FTS3 开始,MATCH '*ux'(以)和 MATCH '*in*'(包含)也受支持?
    • @DerGolem 文档仅提及前缀搜索;不支持后缀。
    • @DerGolem:“contains”只是标准的MATCH 语法,没有通配符。您可能希望检查我链接到的示例文档。但是,正如 CL 所指出的,问题在于查询前缀。
    • WTF!所以,很遗憾,我不能使用 FTS3,因为我需要 所有情况;后缀、前缀和“中间”...
    • 我在示例中添加了一条新记录。 select * from table where word match 'AA*'order by H collat​​e nocase asc 将返回 BAA AA 结果,这不是我想要的。如果我使用类似 'AA%' 的结果将是正确的。
    猜你喜欢
    • 2016-11-02
    • 1970-01-01
    • 2020-01-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多