1
0
Fork 0
mirror of https://github.com/M66B/FairEmail.git synced 2024-12-26 09:47:13 +00:00

Added FTS OR search

This commit is contained in:
M66B 2020-01-16 20:15:32 +01:00
parent 6bc3488d01
commit c90f9bff51
2 changed files with 22 additions and 5 deletions

4
FAQ.md
View file

@ -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.

View file

@ -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();