gpt4 book ai didi

android - FTS4 sqlite MATCH 不工作

转载 作者:行者123 更新时间:2023-11-29 01:29:58 26 4
gpt4 key购买 nike

我在这里尝试了几种方法:

SQLite FTS example doesn't work

这里:

Full text search example in Android (目前我认为最好的教程)

但是,我的搜索返回 0 个结果!

这是我尝试过的:

   String key = "a";
Cursor c = db.query(true, "texts_virtual",
new String[]{"id","title_normalized"},
"title_normalized MATCH '"+key+"'",
null, null, null, null, null);

= 0 个结果;

 String query = "a";
String[] params = {"%" +query+ "%"};

Cursor c = db.rawQuery("SELECT * FROM texts_virtual WHERE title_normalized MATCH ?", params);

= 0 结果太

我知道虚拟表正在正常工作,因为我可以这样做:

String queryText = "a"; //here i test other texts and they worked too
String query = "select * from texts_virtual where title_normalized like ? order by number";
String[] params = {"%" + queryText + "%"};
Cursor c = db.rawQuery(query, params);

所以这证明 texts_virtual 正在运行,查询不起作用,但我不知道为什么,不是错误,什么都没有,只有 0 个结果。

另外,在我让它工作之后,我打算在 2 列中使用多个术语搜索

用户输入“WordA WordB WordC”

它搜索 2 列中的每个单词并返回结果,但这是为了将来的任务....

编辑

表格代码创建:

CREATE TABLE texts (id INTEGER PRIMARY KEY AUTOINCREMENT, title_normalized....);

INSERT INTO texts (id, titulo_normalized...) VALUES (1, 'aaaaaa', ...);

然后继续进行更多的插入,最后是虚拟创建

CREATE VIRTUAL TABLE texts_virtual USING fts4(content="texts", id, title_normalized, ..other fields);

我可以使用 LIKE 查询 texts_virtual 但不能使用 MATCH,匹配返回 0 结果 =/

编辑 2 表格的外观:

Table: texts_virtual
----------------------------
id --- title_normalized
--------------------------
1 --- aaaaaaaaab
2 --- abbbbbbbbb
3 --- bbbbbabbbb
4 --- bbbbbbbbbb

最佳答案

FTS 模块搜索单词(确切定义取决于使用的 tokenizer),或者最多搜索带有前缀的单词。

按照设计匹配单词;它找不到“a”,因为您的数据中没有单词“a”。

如果你想在单词中查找子字符串,你必须使用 LIKE。

关于android - FTS4 sqlite MATCH 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31750893/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com