Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f655c6e4 authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "optimization of searching apps in Chinese" am: a0357329

Original change: https://android-review.googlesource.com/c/platform/packages/apps/Launcher3/+/1425241

Change-Id: Ib6cc9b8979c42f93b7d2666297a46590a6ee6d4d
parents ac8fa290 a0357329
Loading
Loading
Loading
Loading
+17 −0
Original line number Diff line number Diff line
@@ -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;
    }
}
+2 −2
Original line number Diff line number Diff line
@@ -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));