Simplified local search

This commit is contained in:
M66B 2022-10-08 16:11:28 +02:00
parent baea82764d
commit 9bfba36a23
2 changed files with 3 additions and 59 deletions

3
FAQ.md
View File

@ -1146,8 +1146,7 @@ This will result in searching like this:
("apple" AND "banana" AND NOT "cherry") OR "nuts"
```
Search expressions can be used for searching on the device via the search index and for searching on the email server,
but not for searching on the device without search index for performance reasons.
Search expressions can be used for searching on the email server only, and not for searching on the device.
Since version 1.1733 it is possible to save searches, which means that a named entry in the navigation menu will be created to repeat the same search later.
You can save a search after searching by tapping on the save button in the top action bar.

View File

@ -189,62 +189,7 @@ public class Fts4DbHelper extends SQLiteOpenHelper {
Long account, Long folder, long[] exclude,
BoundaryCallbackMessages.SearchCriteria criteria) {
String query = breakText(criteria.query);
List<String> word = new ArrayList<>();
List<String> plus = new ArrayList<>();
List<String> minus = new ArrayList<>();
List<String> opt = new ArrayList<>();
StringBuilder all = new StringBuilder();
for (String w : query.split("\\s+")) {
if (all.length() > 0)
all.append(' ');
if (w.length() > 1 && w.startsWith("+")) {
plus.add(w.substring(1));
all.append(w.substring(1));
} else if (w.length() > 1 && w.startsWith("-")) {
minus.add(w.substring(1));
all.append(w.substring(1));
} else if (w.length() > 1 && w.startsWith("?")) {
opt.add(w.substring(1));
all.append(w.substring(1));
} else {
word.add(w);
all.append(w);
}
}
StringBuilder sb = new StringBuilder();
if (plus.size() + minus.size() + opt.size() > 0) {
if (word.size() > 0)
sb.append(escape(TextUtils.join(" ", word)));
for (String p : plus) {
if (sb.length() > 0)
sb.append(" AND ");
sb.append(escape(p));
}
for (String m : minus) {
if (sb.length() > 0)
sb.append(" NOT ");
sb.append(escape(m));
}
if (sb.length() > 0) {
sb.insert(0, '(');
sb.append(')');
}
for (String o : opt) {
if (sb.length() > 0)
sb.append(" OR ");
sb.append(escape(o));
}
}
String search = (sb.length() > 0 ? sb.toString() : escape(query));
String search = escape(breakText(criteria.query));
String select = "";
if (account != null)
@ -280,7 +225,7 @@ public class Fts4DbHelper extends SQLiteOpenHelper {
}
private static String escape(String word) {
return "\"" + word.replaceAll("\"", "\"\"") + "\"";
return "'" + word.replaceAll("'", "''") + "'";
}
static Cursor getIds(SQLiteDatabase db) {