Refactoring

pull/209/head
M66B 2 years ago
parent 0708f80eb5
commit 2719399e85

@ -788,17 +788,8 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
private static boolean contains(String text, String query) { private static boolean contains(String text, String query) {
if (TextUtils.isEmpty(text)) if (TextUtils.isEmpty(text))
return false; return false;
return Fts4DbHelper.preprocessText(text)
text = text.toLowerCase(); .contains(Fts4DbHelper.preprocessText(query));
query = query.toLowerCase();
query = Normalizer.normalize(query.toLowerCase(), Normalizer.Form.NFKD)
.replaceAll("[\\p{InCombiningDiacriticalMarks}]", "");
text = Normalizer.normalize(text, Normalizer.Form.NFKD)
.replaceAll("[\\p{InCombiningDiacriticalMarks}]", "");
return text.contains(query);
} }
State getState() { State getState() {

@ -134,18 +134,22 @@ 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) {
return Normalizer.normalize(text.trim().toLowerCase(), Normalizer.Form.NFKD)
.replaceAll("[\\p{InCombiningDiacriticalMarks}]", "");
}
private static String breakText(String text) { private static String breakText(String text) {
if (TextUtils.isEmpty(text)) if (TextUtils.isEmpty(text))
return ""; return "";
text = preprocessText(text);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N)
return text; return text;
// https://www.sqlite.org/fts3.html#tokenizer // https://www.sqlite.org/fts3.html#tokenizer
text = Normalizer.normalize(text.toLowerCase(), Normalizer.Form.NFKD)
.replaceAll("[\\p{InCombiningDiacriticalMarks}]", "");
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
android.icu.text.BreakIterator boundary = android.icu.text.BreakIterator.getWordInstance(); android.icu.text.BreakIterator boundary = android.icu.text.BreakIterator.getWordInstance();
boundary.setText(text); boundary.setText(text);
@ -172,7 +176,7 @@ public class Fts4DbHelper extends SQLiteOpenHelper {
" GROUP BY term" + " GROUP BY term" +
" ORDER BY SUM(occurrences) DESC" + " ORDER BY SUM(occurrences) DESC" +
" LIMIT " + max, " LIMIT " + max,
new String[]{query})) { new String[]{preprocessText(query)})) {
while (cursor != null && cursor.moveToNext()) while (cursor != null && cursor.moveToNext())
result.add(cursor.getString(0)); result.add(cursor.getString(0));
} }
@ -185,7 +189,7 @@ public class Fts4DbHelper extends SQLiteOpenHelper {
Long account, Long folder, long[] exclude, Long account, Long folder, long[] exclude,
BoundaryCallbackMessages.SearchCriteria criteria) { BoundaryCallbackMessages.SearchCriteria criteria) {
String query = breakText(criteria.query.trim()); String query = breakText(criteria.query);
List<String> word = new ArrayList<>(); List<String> word = new ArrayList<>();
List<String> plus = new ArrayList<>(); List<String> plus = new ArrayList<>();

Loading…
Cancel
Save