mirror of
https://github.com/M66B/FairEmail.git
synced 2026-04-01 06:38:29 +02:00
Use FTS vocabulary for search suggestions
This commit is contained in:
@@ -39,7 +39,7 @@ public class FtsDbHelper extends SQLiteOpenHelper {
|
||||
|
||||
private static FtsDbHelper instance = null;
|
||||
|
||||
private static final int DATABASE_VERSION = 4;
|
||||
private static final int DATABASE_VERSION = 5;
|
||||
private static final String DATABASE_NAME = "fts.db";
|
||||
|
||||
private FtsDbHelper(Context context) {
|
||||
@@ -68,12 +68,18 @@ public class FtsDbHelper extends SQLiteOpenHelper {
|
||||
", `notes`" +
|
||||
", tokenize = \"unicode61 remove_diacritics 2\")");
|
||||
// https://www.sqlite.org/fts5.html#unicode61_tokenizer
|
||||
|
||||
// https://www.sqlite.org/fts5.html#the_fts5vocab_virtual_table_module
|
||||
db.execSQL("CREATE VIRTUAL TABLE message_terms USING fts5vocab('message', 'row');");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
|
||||
Log.i("FTS upgrade from " + oldVersion + " to " + newVersion);
|
||||
db.execSQL("DROP TABLE `message`");
|
||||
|
||||
db.execSQL("DROP TABLE IF EXISTS `message`");
|
||||
db.execSQL("DROP TABLE IF EXISTS `message_terms`");
|
||||
|
||||
onCreate(db);
|
||||
|
||||
DB.getInstance(context).message().resetFts();
|
||||
@@ -114,6 +120,21 @@ public class FtsDbHelper extends SQLiteOpenHelper {
|
||||
db.delete("message", "rowid = ?", new Object[]{id});
|
||||
}
|
||||
|
||||
static List<String> getSuggestions(SQLiteDatabase db, String query, int max) {
|
||||
List<String> result = new ArrayList<>();
|
||||
|
||||
Cursor cursor = db.query(
|
||||
"SELECT term FROM message_terms" +
|
||||
" WHERE term LIKE ?" +
|
||||
" ORDER BY cnt" +
|
||||
" LIMIT " + max,
|
||||
new Object[]{query});
|
||||
while (cursor != null && cursor.moveToNext())
|
||||
result.add(cursor.getString(0));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static List<Long> match(
|
||||
SQLiteDatabase db,
|
||||
Long account, Long folder,
|
||||
|
||||
Reference in New Issue
Block a user