0

我有一个问题表

    ProblemTable
    id  problemTitle                        problemDescription
    1   machine got hand                    water Motor got jammed
    2   motor is not working                induction motor is not working
    3   water connection is not proper      water connectivity problem in city
    4   electric power machine problem      Electric power generator is not working
    5   power down in my city               Power down in city 

我需要添加搜索功能,可能是关键字搜索或全文搜索,包括描述和标题。就像我搜索“电机”一样

 reasults will be 
    1   machine got hand                    water Motor got jammed
    2   motor is not working                induction motor is not working

如果我按“ power down in city”搜索结果

4   electric power machine problem      Electric power generator is not working 
5   power down in my city               Power down in city
3   water connection is not proper      water connectivity problem in city 

我如何实现这种形式的 sqlite db 全文以及关键字搜索。如果我有 100K 的大量行,什么搜索策略会好?请帮我 。

4

1 回答 1

0

如果你想在 sqlite 中进行全文搜索,你可以使用 fts3

https://sqlite.org/fts3.html

假设您正在使用 SQLiteOpenHelper 语法将是这样的

 // Full-text search index. Update using updateSessionSearchIndex method.
 // Use the porter tokenizer for simple stemming, so that "frustration" matches "frustrated."
db.execSQL("CREATE VIRTUAL TABLE " + Tables.SESSIONS_SEARCH + " USING fts3("
            + BaseColumns._ID + " INTEGER PRIMARY KEY AUTOINCREMENT,"
            + SessionsSearchColumns.BODY + " TEXT NOT NULL,"
            + SessionsSearchColumns.SESSION_ID
                    + " TEXT NOT NULL " + References.SESSION_ID + ","
            + "UNIQUE (" + SessionsSearchColumns.SESSION_ID + ") ON CONFLICT REPLACE,"
            + "tokenize=porter)");
于 2015-06-29T16:36:35.057 回答