Fixed searching for words containing a plus/minus sign

This commit is contained in:
M66B 2022-10-13 21:48:27 +02:00
parent 1d435368ba
commit 2a8dae7caa
2 changed files with 9 additions and 20 deletions

View File

@ -839,28 +839,17 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
return false;
text = Fts4DbHelper.breakText(text);
query = Fts4DbHelper.breakText(query);
boolean plus = false;
boolean minus = false;
List<String> word = new ArrayList<>();
for (String w : query.trim().split("\\s+"))
if ("+".equals(w))
plus = true;
else if ("-".equals(w))
minus = true;
else {
if (plus) {
if (!text.contains(w))
return false;
} else if (minus) {
if (!html && text.contains(w))
return false;
} else
word.add(w);
plus = false;
minus = false;
}
if (w.length() > 1 && w.startsWith("+")) {
if (!text.contains(Fts4DbHelper.preprocessText(w.substring(1))))
return false;
} else if (w.length() > 1 && w.startsWith("-")) {
if (!html && text.contains(Fts4DbHelper.preprocessText(w.substring(1))))
return false;
} else
word.addAll(Arrays.asList(Fts4DbHelper.breakText(w).split("\\s+")));
if (word.size() == 0)
return true;

View File

@ -134,7 +134,7 @@ public class Fts4DbHelper extends SQLiteOpenHelper {
db.delete("message", "rowid = ?", new String[]{Long.toString(id)});
}
private static String preprocessText(String text) {
static String preprocessText(String text) {
return Normalizer.normalize(text.trim().toLowerCase(), Normalizer.Form.NFKD)
.replaceAll("[\\p{InCombiningDiacriticalMarks}]", "");
}