diff options
author | Yorke Lee <yorkelee@google.com> | 2012-12-05 11:48:58 -0800 |
---|---|---|
committer | Yorke Lee <yorkelee@google.com> | 2013-02-04 15:00:39 -0800 |
commit | 697fa0977ea1d4569064c434bb86e9b9fbfc4b12 (patch) | |
tree | 3a9c37cf11033fdff4bffa504f91b5216773b15b /src | |
parent | 81e0da49ca93081c3ef60d634755f39931c88c94 (diff) |
Enable initial matching for Smart Dialling
Allow the name matcher function used by smart dialling to perform
initial matches of the variety 57 - (J)ohn (S)mith
Refactor SmartDialNameMatcher testing method to allow checking multiple
match positions.
Add tests for initial matches
Change-Id: Iadc5e3e8b2f408136c704015d2297e9b520e1065
Diffstat (limited to 'src')
-rw-r--r-- | src/com/android/dialer/dialpad/SmartDialNameMatcher.java | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/com/android/dialer/dialpad/SmartDialNameMatcher.java b/src/com/android/dialer/dialpad/SmartDialNameMatcher.java index 53f564275..6f0f35423 100644 --- a/src/com/android/dialer/dialpad/SmartDialNameMatcher.java +++ b/src/com/android/dialer/dialpad/SmartDialNameMatcher.java @@ -44,6 +44,13 @@ public class SmartDialNameMatcher { '9', '9', '9', '9' // W,X,Y,Z -> 9 }; + // Whether or not we allow matches like 57 - (J)ohn (S)mith + private static final boolean ALLOW_INITIAL_MATCH = true; + + // The maximum length of the initial we will match - typically set to 1 to minimize false + // positives + private static final int INITIAL_LENGTH_LIMIT = 1; + /* * The switch statement in this function was generated using the python code: * from unidecode import unidecode @@ -511,6 +518,34 @@ public class SmartDialNameMatcher { matchList.add(new SmartDialMatchPosition( tokenStart, queryLength + tokenStart + seperatorCount)); return true; + } else if (ALLOW_INITIAL_MATCH && queryStart < INITIAL_LENGTH_LIMIT) { + // we matched the first character. + // branch off and see if we can find another match with the remaining + // characters in the query string and the remaining tokens + //find the next space in the query string + int j = nameStart; + while (j < nameLength && displayName.charAt(j) != ' ') { + j++; + } + // this means there is at least one character left after the space + if (j < nameLength - 1) { + final String remainder = displayName.substring(j + 1); + final ArrayList<SmartDialMatchPosition> partialTemp = + Lists.newArrayList(); + if (matchesCombination( + remainder, query.substring(queryStart + 1), partialTemp)) { + + // store the list of possible match positions + SmartDialMatchPosition.advanceMatchPositions(partialTemp, j + 1); + partialTemp.add(0, + new SmartDialMatchPosition(nameStart, nameStart + 1)); + + // we found a partial token match, store the data in a + // temp buffer and return it if we end up not finding a full + // token match + partial = partialTemp; + } + } } nameStart++; queryStart++; @@ -532,6 +567,13 @@ public class SmartDialNameMatcher { } } } + // if we have no complete match at this point, then we attempt to fall back to the partial + // token match(if any). If we don't allow initial matching (ALLOW_INITIAL_MATCH = false) + // then partial will always be empty. + if (!partial.isEmpty()) { + matchList.addAll(partial); + return true; + } return false; } |