diff options
author | calderwoodra <calderwoodra@google.com> | 2017-08-03 18:46:27 -0700 |
---|---|---|
committer | Eric Erfanian <erfanian@google.com> | 2017-08-04 10:48:36 -0700 |
commit | 9b83df629577464fad4f2c4b1e021cece8270c38 (patch) | |
tree | 8a4b61a3bfb133db226819772d3c1b998a8e1620 /java/com/android/dialer/searchfragment | |
parent | 911a90842eb6af7b4a8a6cc0d07329655eaef8c4 (diff) |
Updated new search filtering criteria to better match current implementation
There were two outstanding issues in the new search criteria:
- Contacts named "Brandon" would be filtered out by query "b"
- Contacts named "Bob" would NOT be filtered out by query "o"
This isn't how our current implementation of search worked and these issues are
resolved by this change by ignoring case sensitivity and doing suffix checks on
names instead of #contains checks.
Bug: 37209462
Test: QueryFilterUtilTest, SearchContactCursorTest
PiperOrigin-RevId: 164214145
Change-Id: I367ed0d862809d28491ae53e7dd8e1a24c824ec9
Diffstat (limited to 'java/com/android/dialer/searchfragment')
-rw-r--r-- | java/com/android/dialer/searchfragment/common/QueryFilteringUtil.java | 17 | ||||
-rw-r--r-- | java/com/android/dialer/searchfragment/cp2/SearchContactCursor.java | 2 |
2 files changed, 18 insertions, 1 deletions
diff --git a/java/com/android/dialer/searchfragment/common/QueryFilteringUtil.java b/java/com/android/dialer/searchfragment/common/QueryFilteringUtil.java index ee6e61c2e..0d22a824c 100644 --- a/java/com/android/dialer/searchfragment/common/QueryFilteringUtil.java +++ b/java/com/android/dialer/searchfragment/common/QueryFilteringUtil.java @@ -60,6 +60,23 @@ public class QueryFilteringUtil { return queryIndex == query.length(); } + /** + * Returns true if the subparts of the name (split by white space) begin with the query. + * + * <p>Examples: + * + * <ul> + * <li>#nameContainsQuery("b", "Brandon") returns true + * <li>#nameContainsQuery("o", "Bob") returns false + * <li>#nameContainsQuery("o", "Bob Olive") returns true + * </ul> + */ + public static boolean nameContainsQuery(String query, String name) { + return Pattern.compile("(^|\\s)" + Pattern.quote(query.toLowerCase())) + .matcher(name.toLowerCase()) + .find(); + } + /** @return true if the number belongs to the query. */ public static boolean numberMatchesNumberQuery(String query, String number) { return PhoneNumberUtils.isGlobalPhoneNumber(query) diff --git a/java/com/android/dialer/searchfragment/cp2/SearchContactCursor.java b/java/com/android/dialer/searchfragment/cp2/SearchContactCursor.java index 51992646a..05e98cc84 100644 --- a/java/com/android/dialer/searchfragment/cp2/SearchContactCursor.java +++ b/java/com/android/dialer/searchfragment/cp2/SearchContactCursor.java @@ -142,7 +142,7 @@ public final class SearchContactCursor implements Cursor { if (TextUtils.isEmpty(query) || QueryFilteringUtil.nameMatchesT9Query(query, previousName) || QueryFilteringUtil.numberMatchesNumberQuery(query, previousMostQualifiedNumber) - || previousName.contains(query)) { + || QueryFilteringUtil.nameContainsQuery(query, previousName)) { queryFilteredPositions.add(previousMostQualifiedPosition); } } |