diff options
author | Makoto Onuki <omakoto@google.com> | 2011-11-14 14:41:34 -0800 |
---|---|---|
committer | Makoto Onuki <omakoto@google.com> | 2011-11-15 14:01:58 -0800 |
commit | f5f038faf7f3ef460e1c11028d467954840e5f6f (patch) | |
tree | a7df42586df288bb7f25a4f7e2bb47616a7b59aa /src/com/android/providers/contacts/SearchIndexManager.java | |
parent | 38f1fd23d523be9d8706b172c338d2a45d8f06ff (diff) | |
download | packages_providers_ContactsProvider-f5f038faf7f3ef460e1c11028d467954840e5f6f.zip packages_providers_ContactsProvider-f5f038faf7f3ef460e1c11028d467954840e5f6f.tar.gz packages_providers_ContactsProvider-f5f038faf7f3ef460e1c11028d467954840e5f6f.tar.bz2 |
Fix search for hyphenated names
This issue was caused by the combination of the fact that we have two
different imcompatible tokenizers for names, and the fact that our
name-normalizer ignroes all non-letter and non-digit characters.
Basically, the name tokenizer used to build index uses ' ' as the separator,
and the one used to tokenize queries use all non-letter, non-digit characters.
Take the name "Double-barrelled" as an example. The full-text search index
for this looks like "doublebarrelled", because it's treated as one token
(because there's no spaces in it), and the normalzier removes all
non-letter/digits.
On the other hand, the query term "double-barrelled" will be split into
"double" "barrelled", and internally it becomes AND-ed prefix matches
"double* AND barrelled*". Beacuse "barrelled*" doesn't match "doublebarrelled"
the query doesn't hit.
So (for now) let's split names with '-' when buidling the index. With this
CL the index will be "double barrelled" and the query "double-barrelled"
(and also "double barrelled") *will* hit this.
Long-term we probably need a better fix.
Bug 5592553
Change-Id: I34bfa8647eec8d203f8ff7fc8a85f42505054c7c
Diffstat (limited to 'src/com/android/providers/contacts/SearchIndexManager.java')
-rw-r--r-- | src/com/android/providers/contacts/SearchIndexManager.java | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/com/android/providers/contacts/SearchIndexManager.java b/src/com/android/providers/contacts/SearchIndexManager.java index b74b3b6..c989fdc 100644 --- a/src/com/android/providers/contacts/SearchIndexManager.java +++ b/src/com/android/providers/contacts/SearchIndexManager.java @@ -35,6 +35,7 @@ import android.util.Log; import java.util.HashSet; import java.util.Set; +import java.util.regex.Pattern; /** * Maintains a search index for comprehensive contact search. @@ -177,11 +178,26 @@ public class SearchIndexManager { mSbTokens.append(token); } + private static final Pattern PATTERN_HYPHEN = Pattern.compile("\\-"); + public void appendName(String name) { if (TextUtils.isEmpty(name)) { return; } + if (name.indexOf('-') < 0) { + // Common case -- no hyphens in it. + appendNameInternal(name); + } else { + // In order to make hyphenated names searchable, let's split names with '-'. + for (String namePart : PATTERN_HYPHEN.split(name)) { + if (!TextUtils.isEmpty(namePart)) { + appendNameInternal(namePart); + } + } + } + } + private void appendNameInternal(String name) { if (mSbName.length() != 0) { mSbName.append(' '); } |