Break text for Chinese, etc

This commit is contained in:
M66B 2022-10-12 10:58:11 +02:00
parent 0991ad8d69
commit 78b05d2f13
2 changed files with 22 additions and 11 deletions

View File

@ -838,18 +838,29 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
if (TextUtils.isEmpty(text)) if (TextUtils.isEmpty(text))
return false; return false;
text = Fts4DbHelper.preprocessText(text); text = Fts4DbHelper.breakText(text);
query = Fts4DbHelper.preprocessText(query); query = Fts4DbHelper.breakText(query);
boolean plus = false;
boolean minus = 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("+") || w.startsWith("-"))) { if ("+".equals(w))
if (w.startsWith("+") && !text.contains(w.substring(1))) plus = true;
return false; else if ("-".equals(w))
if (w.startsWith("-") && text.contains(w.substring(1))) minus = true;
return false; else {
} else if (plus) {
word.add(w); if (!text.contains(w))
return false;
} else if (minus) {
if (text.contains(w))
return false;
} else
word.add(w);
plus = false;
minus = false;
}
if (word.size() == 0) if (word.size() == 0)
return true; return true;

View File

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