簡體   English   中英

FTS4 sqlite MATCH 不起作用

[英]FTS4 sqlite MATCH not working

我從這里嘗試了幾種方法:

SQLite FTS 示例不起作用

和這里:

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 Results;

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

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

= 0 Results too

我知道虛擬表正常工作,因為我可以這樣做:

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”

它搜索 2columns 中的每個單詞並返回結果,但這是為了將來的任務....

編輯

表代碼創建:

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 模塊搜索單詞(確切的定義取決於所使用的標記器),或者最多搜索帶有前綴的單詞。

按照設計匹配單詞; 它找不到“a”,因為您的數據中沒有單詞“a”。

如果要在單詞中查找子字符串,則必須使用 LIKE。

您正在使用 % 作為小丑。 在 FTS 請求中,您必須使用 * 代替。

LIKE "%word%"

MATCH "*word*"

我注意到對於非常短的單詞(少於 3 個字母),LIKE 比 MATCH 快。 對於更長的單詞,MATCH 更快。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM