mirror of
https://github.com/oxen-io/session-android.git
synced 2025-02-17 15:48:26 +00:00
Break FTS queries into multiple prefix queries.
Previously, we made each full-text search query a single prefix query. That means that the query "do c" would turn into "do c*". That means it would match "do cat" but not "dog cat". Now, we make each token a prefix query. So "do c" would turn into "do* c*". That means it would match both "do cat" and "dog cat".
This commit is contained in:
parent
3563efc7de
commit
89fd7dda23
@ -2,12 +2,16 @@ package org.thoughtcrime.securesms.database;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.util.Log;
|
|
||||||
|
import com.annimon.stream.Stream;
|
||||||
|
|
||||||
import net.sqlcipher.Cursor;
|
import net.sqlcipher.Cursor;
|
||||||
import net.sqlcipher.database.SQLiteDatabase;
|
import net.sqlcipher.database.SQLiteDatabase;
|
||||||
|
|
||||||
import org.thoughtcrime.securesms.database.helpers.SQLCipherOpenHelper;
|
import org.thoughtcrime.securesms.database.helpers.SQLCipherOpenHelper;
|
||||||
|
import org.thoughtcrime.securesms.util.Util;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Contains all databases necessary for full-text search (FTS).
|
* Contains all databases necessary for full-text search (FTS).
|
||||||
@ -81,7 +85,10 @@ public class SearchDatabase extends Database {
|
|||||||
public Cursor queryMessages(@NonNull String query) {
|
public Cursor queryMessages(@NonNull String query) {
|
||||||
SQLiteDatabase db = databaseHelper.getReadableDatabase();
|
SQLiteDatabase db = databaseHelper.getReadableDatabase();
|
||||||
|
|
||||||
String prefixQuery = query + '*';
|
List<String> tokens = Stream.of(query.split(" ")).filter(s -> s.trim().length() > 0).toList();
|
||||||
|
String prefixQuery = Util.join(tokens, "* ");
|
||||||
|
|
||||||
|
prefixQuery += "*";
|
||||||
|
|
||||||
Cursor cursor = db.rawQuery(MESSAGES_QUERY, new String[] { prefixQuery, prefixQuery });
|
Cursor cursor = db.rawQuery(MESSAGES_QUERY, new String[] { prefixQuery, prefixQuery });
|
||||||
setNotifyConverationListListeners(cursor);
|
setNotifyConverationListListeners(cursor);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user