Refactoring

This commit is contained in:
M66B 2022-09-30 15:10:14 +02:00
parent 0708f80eb5
commit 2719399e85
2 changed files with 11 additions and 16 deletions

View File

@ -788,17 +788,8 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
private static boolean contains(String text, String query) {
if (TextUtils.isEmpty(text))
return false;
text = text.toLowerCase();
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);
return Fts4DbHelper.preprocessText(text)
.contains(Fts4DbHelper.preprocessText(query));
}
State getState() {

View File

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