summaryrefslogtreecommitdiffstats
path: root/src/com/android/settings/search
diff options
context:
space:
mode:
authorFabrice Di Meglio <fdimeglio@google.com>2014-05-28 16:17:24 -0700
committerFabrice Di Meglio <fdimeglio@google.com>2014-05-28 16:20:38 -0700
commit363348dd8bd1e58d8b7faa8a9405589e41d28e48 (patch)
tree0ab119507cffe961ad26d5babe5ad0dec80745be /src/com/android/settings/search
parenta8ac78b3925a0b463c2df37a7c83d8f15222a601 (diff)
downloadpackages_apps_Settings-363348dd8bd1e58d8b7faa8a9405589e41d28e48.zip
packages_apps_Settings-363348dd8bd1e58d8b7faa8a9405589e41d28e48.tar.gz
packages_apps_Settings-363348dd8bd1e58d8b7faa8a9405589e41d28e48.tar.bz2
FR #15314612 - Enable search on non accentuated chars
- update normalization step. Use a Normalizer for a string decomposition to the NFD form and remove those diacritics with a "\\p{InCombiningDiacriticalMarks}+" pattern. See bug #15314612 Search - need to be able to search and have results with non accentuated chars Change-Id: Ifaf4cd2ca2fb712e1c6f5f5272f942dda99464e4
Diffstat (limited to 'src/com/android/settings/search')
-rw-r--r--src/com/android/settings/search/Index.java24
1 files changed, 16 insertions, 8 deletions
diff --git a/src/com/android/settings/search/Index.java b/src/com/android/settings/search/Index.java
index 64ef985..b1d21af 100644
--- a/src/com/android/settings/search/Index.java
+++ b/src/com/android/settings/search/Index.java
@@ -45,6 +45,7 @@ import org.xmlpull.v1.XmlPullParserException;
import java.io.IOException;
import java.lang.reflect.Field;
+import java.text.Normalizer;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
@@ -54,6 +55,7 @@ import java.util.Locale;
import java.util.Map;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.regex.Pattern;
import static android.provider.SearchIndexablesContract.COLUMN_INDEX_NON_INDEXABLE_KEYS_KEY_VALUE;
import static android.provider.SearchIndexablesContract.COLUMN_INDEX_RAW_RANK;
@@ -150,8 +152,11 @@ public class Index {
private static final List<String> EMPTY_LIST = Collections.<String>emptyList();
-
private static Index sInstance;
+
+ private static final Pattern REMOVE_DIACRITICALS_PATTERN
+ = Pattern.compile("\\p{InCombiningDiacriticalMarks}+");
+
private final AtomicBoolean mIsAvailable = new AtomicBoolean(false);
private final UpdateData mDataToProcess = new UpdateData();
private Context mContext;
@@ -914,13 +919,13 @@ public class Index {
String intentAction, String intentTargetPackage, String intentTargetClass,
boolean enabled, String key) {
- String updatedTitle = normalizeHyphen(title);
- String updatedSummaryOn = normalizeHyphen(summaryOn);
- String updatedSummaryOff = normalizeHyphen(summaryOff);
+ final String updatedTitle = normalizeHyphen(title);
+ final String updatedSummaryOn = normalizeHyphen(summaryOn);
+ final String updatedSummaryOff = normalizeHyphen(summaryOff);
- String normalizedTitle = normalizeString(updatedTitle);
- String normalizedSummaryOn = normalizeString(updatedSummaryOn);
- String normalizedSummaryOff = normalizeString(updatedSummaryOff);
+ final String normalizedTitle = normalizeString(updatedTitle);
+ final String normalizedSummaryOn = normalizeString(updatedSummaryOn);
+ final String normalizedSummaryOff = normalizeString(updatedSummaryOff);
updateOneRow(database, locale,
updatedTitle, normalizedTitle, updatedSummaryOn, normalizedSummaryOn,
@@ -934,7 +939,10 @@ public class Index {
}
private static String normalizeString(String input) {
- return (input != null) ? input.replaceAll(HYPHEN, EMPTY) : EMPTY;
+ final String nohyphen = (input != null) ? input.replaceAll(HYPHEN, EMPTY) : EMPTY;
+ final String normalized = Normalizer.normalize(nohyphen, Normalizer.Form.NFD);
+
+ return REMOVE_DIACRITICALS_PATTERN.matcher(normalized).replaceAll("").toLowerCase();
}
private void updateOneRow(SQLiteDatabase database, String locale,