从Sqlite数据库在Android应用程序中添加高效搜索功能
我有一个问题表从Sqlite数据库在Android应用程序中添加高效搜索功能,android,sqlite,search,full-text-search,keyword-search,Android,Sqlite,Search,Full Text Search,Keyword Search,我有一个问题表 ProblemTable id problemTitle problemDescription 1 machine got hand water Motor got jammed 2 motor is not working induction motor is not working 3 water connec
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
我需要添加搜索功能,这可能是关键字搜索或全文搜索,从描述和标题。就像我通过“马达”搜索一样
如果我通过“城市断电”
进行搜索
搜索结果
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全文搜索和kewords搜索。如果我没有100K行,什么搜索策略会更好?
请帮帮我 如果您想在sqlite中进行全文搜索,可以使用fts3 假设您使用的是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)");
我投票决定不讨论这个问题,因为OP似乎没有尝试过任何东西。@nicael:我想弄清楚这个问题,我是否需要从表中对搜索文本中的每个单词执行多个查询,并使用“Like%”,或者你们可以帮助的任何新想法,这可能是一个更好的解决方案。请给出一些解决方案。这个问题有被关闭的危险。要求家庭作业帮助的问题必须包括到目前为止你为解决问题所做工作的总结,以及对你解决问题的困难的描述。
// 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)");