我从这里尝试了几种方法:
I've tried several methods from here:
SQLite FTS 示例不起作用
这里:
Android 中的全文搜索示例(我认为目前最好的教程)
Full text search example in Android (best tutorial so far i think)
但是,我的搜索返回了 0 个结果!
However, my search returns 0 results!
这是我尝试过的:
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 结果也是
我知道虚拟表可以正常工作,因为我可以这样做:
I know that the virtual table is correctly working because I can do this:
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 个结果.
so this prove that the texts_virtual is working, what is not working are the queries, but I don't know why, not error, nothing, just 0 results.
此外,在我使其工作后,我计划在 2 列中使用多词搜索
Also after I make it work, I'm planning to use multiple terms search in 2 columns
用户类型WordA WordB WordC"
user type "WordA WordB WordC"
它搜索 2columns 中的每个单词并返回结果,但这是为了将来的任务....
it search for each word in the 2columns and return the results, but this if for a future task....
编辑
表代码创建:
CREATE TABLE texts (id INTEGER PRIMARY KEY AUTOINCREMENT, title_normalized....); INSERT INTO texts (id, titulo_normalized...) VALUES (1, 'aaaaaa', ...);继续进行更多的插入,最后是虚拟创建
and go on for more inserts, and at the end the virtual creation
CREATE VIRTUAL TABLE texts_virtual USING fts4(content="texts", id, title_normalized, ..other fields);我可以使用 LIKE 查询 texts_virtual,但不能使用 MATCH,匹配返回 0 结果 =/
i can query texts_virtual using LIKE but not MATCH, match return 0 results =/
编辑 2 表格的外观:
Table: texts_virtual ---------------------------- id --- title_normalized -------------------------- 1 --- aaaaaaaaab 2 --- abbbbbbbbb 3 --- bbbbbabbbb 4 --- bbbbbbbbbb 推荐答案FTS 模块搜索单词(其中的确切定义取决于 tokenizer 使用),或者至多用于带有前缀的单词.
The FTS module searches for words (where the exact definition depends on the tokenizer used), or at best for words with a prefix.
按照设计匹配单词;它没有找到a",因为您的数据中没有a"这个词.
MATCH words as designed; it does not find "a" because there is no word "a" in your data.
如果要查找单词内的子串,必须使用 LIKE.
If you want to find substrings inside words, you must use LIKE.
更多推荐
FTS4 sqlite MATCH 不起作用
发布评论