日志
PeopleList搜索机制
2017-09-28 17:48
MTKfaqPeopleList搜索机制
Contacts数据库结构中,联系人列表显示的名字保存于raw_contacts表的display_name中(假如为110),而data表中保存的名字包括两部分(则data1中保存的是“卡的01”,data3中保存是“110”),而联系人搜索时,是以data1中数据为全名,建立姓名索引的,故搜索“110”不能搜索出此联系人 contacts2.db 数据库中name_lookup表中的normalized name中保存是非特殊字符的名称,一般用于通过全名搜索联系人(例如,新建一个联系人,李三,可以通过name_lookup表查询当前是否已经存在名为李三的联系人),其相应处理函数为 NameNormalizer.java (alps\packages\providers\contactsprovider\src\com\android\providers\contacts) /** * Converts the supplied name to a string that can be used to perform approximate matching * of names. It ignores non-letter, non-digit characters, and removes accents. */ public static String normalize(String name) { CollationKey key = getCompressingCollator().getCollationKey(lettersAndDigitsOnly(name)); return Hex.encodeHex(key.toByteArray(), true); } 而联系人名字搜索的时候,用的是search_index表,其中用于保存名字搜索组合的表是search_index_content,相应处理函数为 NameLookupBuilder.java (alps\packages\providers\contactsprovider\src\com\android\providers\contacts) public void appendToSearchIndex(IndexBuilder builder, String name, int fullNameStyle) { //将全名拆分为姓和名 int tokenCount = mSplitter.tokenize(mNames, name); if (tokenCount == 0) { return; } for (int i = 0; i < tokenCount; i++) { builder.appendName(mNames); } /** * Insert more name indexes according to locale specifies for those locales * for which we have alternative shorthand name methods (eg, Pinyin for * Chinese, Romaji for Japanese). */ appendNameShorthandLookup(builder, name, fullNameStyle); /** * Insert more name indexes according to locale specifies. */ appendNameLookupForLocaleBasedName(builder, name, fullNameStyle); } 经过以上处理,一个联系人的全名就被拆分了各种可能的搜索组合。 针对此问题,搜索RASHID,无法搜索出联系人RASHID GM,是因为其data1中数据为GMRASHID,其对应search_index_content中的内容为333F49274B35372D(编码前为GMRASHID)。而搜索GMRA则可以搜索到此联系人。 比较联系人RASHID ASIF,可以看到其data1中数据为RASHID ASIF,其对应的search_index_content中的内容为274B3731(编码前为RASHID) 49274B35372D(编码前为ASIFRASHID),因此搜索RASHID和ASIFR均可以搜索此联系人。 数据库中name_lookup表中的normalized name中保存是非特殊字符的名称,一般用于通过全名搜索联系人(例如,新建一个联系人,李三,可以通过name_lookup表查询当前是否已经存在名为李三的联系人),其相应处理函数为 NameNormalizer.java (alps\packages\providers\contactsprovider\src\com\android\providers\contac ts) /** * Converts the supplied name to a string that can be used to perform approximate matching * of names. It ignores non-letter, non-digit characters, and removes accents. */ public static String normalize(String name) { CollationKey key = getCompressingCollator().getCollationKey(lettersAndDigitsOnly(name)); return Hex.encodeHex(key.toByteArray(), true); } 而联系人名字搜索的时候,用的是search_index表,其中用于保存名字搜索组合的表是search_index_content,相应处理函数为 NameLookupBuilder.java (alps\packages\providers\contactsprovider\src\com\android\providers\contac ts) public void appendToSearchIndex(IndexBuilder builder, String name, int fullNameStyle) { //将全名拆分为姓和名 int tokenCount = mSplitter.tokenize(mNames, name); if (tokenCount == 0) { return; } for (int i = 0; i < tokenCount; i++) { builder.appendName(mNames); } /** * Insert more name indexes according to locale specifies for those locales * for which we have alternative shorthand name methods (eg, Pinyin for * Chinese, Romaji for Japanese). */ appendNameShorthandLookup(builder, name, fullNameStyle); /** * Insert more name indexes according to locale specifies. */ appendNameLookupForLocaleBasedName(builder, name, fullNameStyle); } 经过以上处理,一个联系人的全名就被拆分了各种可能的搜索组合。比如英文名, first@second#three,拆分成了firstsecondthree, first, second, three, 因此搜索前面4个字符串,或此字符串的前几个字母,均能搜索出此联系人。(即f, fi,fir, s, se等均能搜索到,而i, ir irs均搜不到)。 比如中文名,刘德华,拆分成了“刘德华”、德华、华,因为中文还支持拼音(因为ContactLocaleUtils.java (alps\packages\providers\contactsprovider\src\com\android\providers\contacts)中SimplifiedChineseContactUtils有定义getNameLookupKeys()),所以还有“liudehua” , dehua, hua及首字母组合“ ldh”。 比如韩国人名, ,因为韩国人姓名处理有专门的函数appendKoreanNameConsonantsLookup()(在appendNameLookupForLocaleBasedName()中会调用到),拆分成、 的组合,故贵司测试到的“输入“”,检索不到,而输入“ ”就没有问题” |
下一篇: 关于触摸屏的供电配置
上一篇: MTK 4G仪器配置注意事项,影响功耗