Added FTS OR search

pull/172/head
M66B 5 years ago
parent 6bc3488d01
commit c90f9bff51

@ -693,6 +693,10 @@ to check if the searched text is contained in the file, which is a relative expe
In the *miscellaneous settings* you can enable *Build search index* to significantly increase the speed of searching on the device,
but be aware that this will increase battery usage and significantly increase storage space usage too.
Searching using the search index is by default AND, so searching for *apple orange* will search for apple AND orange.
Words separated by commas results in searching for OR, so for example *apple, orange* will search for apple OR orange.
Both can be combined, so searching for *apple, orange banana* will search for apple OR (orange AND banana).
Using the search index is a pro feature.
Searching messages on the device is a free feature, searching messages on the server is a pro feature.

@ -94,13 +94,26 @@ public class FtsDbHelper extends SQLiteOpenHelper {
}
static List<Long> match(SQLiteDatabase db, Long folder, String query) {
String[] parts = query.split("\\s+");
StringBuilder sb = new StringBuilder();
for (String part : parts) {
for (String or : query.split(",")) {
if (sb.length() > 0)
sb.append(" AND ");
part = part.replaceAll("\"", "\"\"");
sb.append("\"").append(part).append("\"");
sb.append(" OR ");
boolean first = true;
sb.append("(");
for (String and : or.trim().split("\\s+")) {
if (first)
first = false;
else
sb.append(" AND ");
// Escape quotes
String term = and.replaceAll("\"", "\"\"");
// Quote search term
sb.append("\"").append(term).append("\"");
}
sb.append(")");
}
String search = sb.toString();

Loading…
Cancel
Save