【问题标题】:Add Efficient searching feature in Android App from Sqlite Database从 Sqlite 数据库在 Android 应用程序中添加高效搜索功能
【发布时间】:2015-09-16 04:24:34
【问题描述】:

我有一个问题表

    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 

我需要添加搜索功能,可以是关键字搜索或全文搜索,包括描述和标题。就像我按 "motor"

搜索
 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的大量行,什么搜索策略会好? 请帮我 。

【问题讨论】:

  • 我投票决定将此问题作为题外话结束,因为 OP 似乎没有尝试过任何事情。
  • @nicael :我试图找出问题所在,我是否需要从表中对搜索文本中的每个单词使用“Like %”进行多次查询,或者你们可以在哪里找到任何新想法帮助,可能是一个更好的解决方案。请给出一些解决方案。
  • 这个问题有被关闭的风险。要求家庭作业帮助的问题必须包括您迄今为止为解决问题所做的工作的总结,以及您在解决问题时遇到的困难的描述。

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


【解决方案1】:

如果你想在 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)");

【讨论】:

    猜你喜欢
    • 2021-07-26
    • 1970-01-01
    • 2016-09-11
    • 1970-01-01
    • 1970-01-01
    • 2011-11-11
    • 1970-01-01
    • 2016-08-01
    • 2017-09-02
    相关资源
    最近更新 更多