From 97cc6df21dfd4dc4865d93022341150f468758f8 Mon Sep 17 00:00:00 2001 From: zhaoguomanong Date: Thu, 10 Sep 2020 19:13:02 +0800 Subject: [PATCH] optimization of searching apps in Chinese Signed-off-by: zhaoguomanong Change-Id: Id322eb8b5249d6163da8a5d3476a6cf9500ad6bb --- .../search/DefaultAppSearchAlgorithm.java | 17 +++++++++++++++++ .../search/DefaultAppSearchAlgorithmTest.java | 4 ++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/com/android/launcher3/allapps/search/DefaultAppSearchAlgorithm.java b/src/com/android/launcher3/allapps/search/DefaultAppSearchAlgorithm.java index f72a9888cf..bcb54276e4 100644 --- a/src/com/android/launcher3/allapps/search/DefaultAppSearchAlgorithm.java +++ b/src/com/android/launcher3/allapps/search/DefaultAppSearchAlgorithm.java @@ -81,6 +81,10 @@ public class DefaultAppSearchAlgorithm implements SearchAlgorithm { return false; } + if (requestSimpleFuzzySearch(query)) { + return title.toLowerCase().contains(query); + } + int lastType; int thisType = Character.UNASSIGNED; int nextType = Character.getType(title.codePointAt(0)); @@ -181,4 +185,17 @@ public class DefaultAppSearchAlgorithm implements SearchAlgorithm { return new StringMatcher(); } } + + private static boolean requestSimpleFuzzySearch(String s) { + for (int i = 0; i < s.length(); ) { + int codepoint = s.codePointAt(i); + i += Character.charCount(codepoint); + switch (Character.UnicodeScript.of(codepoint)) { + case HAN: + //Character.UnicodeScript.HAN: use String.contains to match + return true; + } + } + return false; + } } diff --git a/tests/src/com/android/launcher3/allapps/search/DefaultAppSearchAlgorithmTest.java b/tests/src/com/android/launcher3/allapps/search/DefaultAppSearchAlgorithmTest.java index bdf01f3cf9..39709a9539 100644 --- a/tests/src/com/android/launcher3/allapps/search/DefaultAppSearchAlgorithmTest.java +++ b/tests/src/com/android/launcher3/allapps/search/DefaultAppSearchAlgorithmTest.java @@ -68,8 +68,8 @@ public class DefaultAppSearchAlgorithmTest { assertTrue(DefaultAppSearchAlgorithm.matches(getInfo("电子邮件"), "电", MATCHER)); assertTrue(DefaultAppSearchAlgorithm.matches(getInfo("电子邮件"), "电子", MATCHER)); - assertFalse(DefaultAppSearchAlgorithm.matches(getInfo("电子邮件"), "子", MATCHER)); - assertFalse(DefaultAppSearchAlgorithm.matches(getInfo("电子邮件"), "邮件", MATCHER)); + assertTrue(DefaultAppSearchAlgorithm.matches(getInfo("电子邮件"), "子", MATCHER)); + assertTrue(DefaultAppSearchAlgorithm.matches(getInfo("电子邮件"), "邮件", MATCHER)); assertFalse(DefaultAppSearchAlgorithm.matches(getInfo("Bot"), "ba", MATCHER)); assertFalse(DefaultAppSearchAlgorithm.matches(getInfo("bot"), "ba", MATCHER));