【问题标题】:Android SQLite additional WHERE condition after MATCHMATCH 后的 Android SQLite 附加 WHERE 条件
【发布时间】:2020-05-11 07:06:28
【问题描述】:

在 Android SQLite 中,我得到了这样的表格

domainObjectId: String // like '9876543210'
name: String
description: String

我想在此使用 FTS 进行搜索,而不用担心变音符号,但我想让用户也通过键入部分对象 ID(例如最后 4 个字符)来选择

我选择喜欢

`SELECT * FROM tabel LEFT JOIN tabel_fts on tabel_fts.domainObjectId = tabel.domainObjectId WHERE tabel_fts MATCH '3210*' OR tabel.domainObjectId LIKE '%3210%'

但作为回报我得到错误

unable to use function MATCH in the requested context (code 1 SQLITE_ERROR);

这是否可以添加附加条件以使用MATCH 进行选择?

【问题讨论】:

    标签: android sqlite full-text-search android-room


    【解决方案1】:

    尝试将“MATCH”删除到单独的“SELECT”中:

    `SELECT * FROM tabel LEFT JOIN (select * from tabel_fts WHERE tabel_fts.domainObjectId MATCH '3210*') as tabel_fts WHERE tabel.domainObjectId LIKE '%3210%' OR table_fts.ID IS   NOT NULL
    

    顺便说一句:

    1. 在您的“WHERE tabel_fts”中,您似乎遗漏了一个列名
    2. 表 JOINm 中没有“ON”条件,只有“WHERE”。没关系?使用 UNION 会更好吗?

    【讨论】:

    • WHERE tabel_fts.domainObjectId MATCH '3210*' 将仅匹配 objectID,没有名称和描述 WHERE tabel_fts MATCH '3210* 将尝试在整个 fts 表上进行匹配。在这种情况下,您的 SELECT 将起作用,但如果我尝试匹配名称,它将不起作用,内部选择将返回值,但外部 SELECT 由于 LIKE 语句将不返回任何值。
    • 好的,我知道你在哪里。至于外部|内部选择的问题 - 为什么选择左连接? UNION(或 Cross JOIN)不是选项?
    • 看起来可行,SELECT * FROM tabel WHERE domainObjectId IN ( SELECT domainObjectId FROM tabel WHERE domainObjectId LIKE "%phase%" UNION SELECT number FROM tabel_fts WHERE tabel_fts MATCH "phase*" )
    • 可以在没有 UNION 的情况下完成事件 ;) SELECT * FROM tabel WHERE domainObjectId IN (SELECT domainObjectId FROM tabel_fts WHERE tabel_fts MATCH 'phase*' ) OR domainObjectId LIKE '%phase%'
    • 是的。有很多选择。唯一的条件是 MATCH 不应该在它自己的 SELECT 之外使用。
    猜你喜欢
    • 2016-11-25
    • 1970-01-01
    • 2022-12-17
    • 1970-01-01
    • 1970-01-01
    • 2014-02-09
    • 2019-04-04
    • 1970-01-01
    • 2012-06-28
    相关资源
    最近更新 更多