Allow local ? search

pull/214/head
M66B 7 months ago
parent a7b0fd2120
commit 5c380c1d1b

@ -276,19 +276,22 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
List<String> word = new ArrayList<>(); List<String> word = new ArrayList<>();
List<String> plus = new ArrayList<>(); List<String> plus = new ArrayList<>();
List<String> minus = new ArrayList<>(); List<String> minus = new ArrayList<>();
List<String> opt = new ArrayList<>();
if (criteria.query != null) { if (criteria.query != null) {
for (String w : criteria.query.trim().split("\\s+")) for (String w : criteria.query.trim().split("\\s+"))
if (w.length() > 1 && w.startsWith("+")) if (w.length() > 1 && w.startsWith("+"))
plus.add(w.substring(1)); plus.add(w.substring(1));
else if (w.length() > 1 && w.startsWith("-")) else if (w.length() > 1 && w.startsWith("-"))
minus.add(w.substring(1)); minus.add(w.substring(1));
else if (w.length() > 1 && w.startsWith("?"))
opt.add(w.substring(1));
else else
word.add(w); word.add(w);
if (word.size() == 0 && plus.size() > 0) if (word.size() == 0 && plus.size() > 0)
word.add(plus.get(0)); word.add(plus.get(0));
} }
if (criteria.fts && word.size() > 0 && !criteria.in_headers && !criteria.in_html) { if (criteria.fts && word.size() > 0 && opt.size() == 0 && !criteria.in_headers && !criteria.in_html) {
if (state.ids == null) { if (state.ids == null) {
SQLiteDatabase sdb = Fts4DbHelper.getInstance(context); SQLiteDatabase sdb = Fts4DbHelper.getInstance(context);
state.ids = Fts4DbHelper.match(sdb, account, folder, exclude, criteria, TextUtils.join(" ", word)); state.ids = Fts4DbHelper.match(sdb, account, folder, exclude, criteria, TextUtils.join(" ", word));
@ -331,7 +334,8 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
while (found < pageSize && !state.destroyed) { while (found < pageSize && !state.destroyed) {
if (state.matches == null || if (state.matches == null ||
(state.matches.size() > 0 && state.index >= state.matches.size())) { (state.matches.size() > 0 && state.index >= state.matches.size())) {
String query = (word.size() == 0 ? null : '%' + TextUtils.join("%", word) + '%'); String query = (word.size() == 0 || opt.size() > 0
? null : '%' + TextUtils.join("%", word) + '%');
state.matches = db.message().matchMessages( state.matches = db.message().matchMessages(
account, folder, exclude, account, folder, exclude,
query, query,
@ -372,7 +376,8 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
state.index = i + 1; state.index = i + 1;
TupleMatch match = state.matches.get(i); TupleMatch match = state.matches.get(i);
boolean matched = (criteria.query == null || Boolean.TRUE.equals(match.matched)); boolean matched = (opt.size() == 0 &&
(criteria.query == null || Boolean.TRUE.equals(match.matched)));
if (!matched) { if (!matched) {
EntityMessage message = db.message().getMessage(match.id); EntityMessage message = db.message().getMessage(match.id);
@ -899,6 +904,7 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
text = Fts4DbHelper.processBreakText(text); text = Fts4DbHelper.processBreakText(text);
boolean or = false;
List<String> word = new ArrayList<>(); List<String> word = new ArrayList<>();
for (String w : query.trim().split("\\s+")) for (String w : query.trim().split("\\s+"))
if (w.length() > 1 && w.startsWith("+")) { if (w.length() > 1 && w.startsWith("+")) {
@ -907,11 +913,15 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
} else if (w.length() > 1 && w.startsWith("-")) { } else if (w.length() > 1 && w.startsWith("-")) {
if (!html && text.contains(Fts4DbHelper.preprocessText(w.substring(1)))) if (!html && text.contains(Fts4DbHelper.preprocessText(w.substring(1))))
return false; return false;
} else if (w.length() > 1 && w.startsWith("?")) {
or = true;
if (text.contains(Fts4DbHelper.preprocessText(w.substring(1))))
return true;
} else } else
word.addAll(Arrays.asList(Fts4DbHelper.processBreakText(w).split("\\s+"))); word.addAll(Arrays.asList(Fts4DbHelper.processBreakText(w).split("\\s+")));
if (word.size() == 0) if (word.size() == 0)
return true; return !or;
// \b is limited to [0-9A-Za-z_] // \b is limited to [0-9A-Za-z_]
String b = "(^|\\s+)"; String b = "(^|\\s+)";
@ -1043,9 +1053,7 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
return false; return false;
for (String w : query.trim().split("\\s+")) for (String w : query.trim().split("\\s+"))
if (w.length() > 1 && w.startsWith("?")) if (w.length() > FROM.length() && w.startsWith(FROM))
return true;
else if (w.length() > FROM.length() && w.startsWith(FROM))
return true; return true;
else if (w.length() > TO.length() && w.startsWith(TO)) else if (w.length() > TO.length() && w.startsWith(TO))
return true; return true;

Loading…
Cancel
Save