Fixing missing punctuation for punctuation search case.
Previous CL I9cbdf10d21c79f53bc621bacb7eeeb95a6a2435f fixed missing
punctuation at the start when searching without punctuation. (e.g.
{hello})
This CL fixes the case where leading punctuation is missing if you searched
with a leading punctuation. (e.g. {'hello}). The content provider
uses a different code path when it detects multi-words and snippeting
is actually done in sqlite using the FTS snippet method. The check for
multi-word was treating {'hello} as two words.
This means that multi-word searches will still have this issue as it still
uses the sqlite snippet method. Leaving this to a separate CL since it's
a riskier change.
Bug: 5929143
Change-Id: I4c2451b2e8eb47d5831e6ef6cfcca538ff3599b9
diff --git a/src/com/android/providers/contacts/ContactsProvider2.java b/src/com/android/providers/contacts/ContactsProvider2.java
index d746170..1c4c1f3 100644
--- a/src/com/android/providers/contacts/ContactsProvider2.java
+++ b/src/com/android/providers/contacts/ContactsProvider2.java
@@ -8283,7 +8283,16 @@
* @return a boolean indicating if the query is one word or not
*/
private boolean isSingleWordQuery(String query) {
- return query.split(QUERY_TOKENIZER_REGEX).length == 1;
+ // Split can remove empty trailing tokens but cannot remove starting empty tokens so we
+ // have to loop.
+ String[] tokens = query.split(QUERY_TOKENIZER_REGEX, 0);
+ int count = 0;
+ for (String token : tokens) {
+ if (!"".equals(token)) {
+ count++;
+ }
+ }
+ return count == 1;
}
/**