diff options
author | Dmitri Plotnikov <dplotnikov@google.com> | 2011-02-10 12:00:23 -0800 |
---|---|---|
committer | Dmitri Plotnikov <dplotnikov@google.com> | 2011-02-10 12:00:23 -0800 |
commit | 197411a6cc3f81b94a34ca207f267d43d8548f04 (patch) | |
tree | c2a2c71fda8e1417b4e048f00eae6d306a9e4dba | |
parent | bd9abbb6b03b4ec1e28ad3fa2fcba5d1eb8609ea (diff) | |
download | packages_providers_ContactsProvider-197411a6cc3f81b94a34ca207f267d43d8548f04.zip packages_providers_ContactsProvider-197411a6cc3f81b94a34ca207f267d43d8548f04.tar.gz packages_providers_ContactsProvider-197411a6cc3f81b94a34ca207f267d43d8548f04.tar.bz2 |
Full text search: removing organization from name lookup
It no longer needs to be in the name lookup table,
because we now have it in the search index and we
don't use it for aggregation.
Bug: 2078420
Change-Id: Iaab128513ff29a38f97c7d880c2aae668a3ef865
4 files changed, 37 insertions, 110 deletions
diff --git a/src/com/android/providers/contacts/ContactsDatabaseHelper.java b/src/com/android/providers/contacts/ContactsDatabaseHelper.java index 73c43ae..51829ec 100644 --- a/src/com/android/providers/contacts/ContactsDatabaseHelper.java +++ b/src/com/android/providers/contacts/ContactsDatabaseHelper.java @@ -92,7 +92,7 @@ import java.util.Locale; * 500-599 Honeycomb-MR1 * </pre> */ - static final int DATABASE_VERSION = 500; + static final int DATABASE_VERSION = 501; private static final String DATABASE_NAME = "contacts2.db"; private static final String DATABASE_PRESENCE = "presence_db"; @@ -392,7 +392,6 @@ import java.util.Locale; public static final int NAME_COLLATION_KEY = 2; public static final int NICKNAME = 3; public static final int EMAIL_BASED_NICKNAME = 4; - public static final int ORGANIZATION = 5; public static final int NAME_SHORTHAND = 6; public static final int NAME_CONSONANTS = 7; @@ -1775,6 +1774,11 @@ import java.util.Locale; oldVersion = 500; } + if (oldVersion < 501) { + upgradeToVersion501(db); + oldVersion = 501; + } + if (upgradeViewsAndTriggers) { createContactsViews(db); createGroupsView(db); @@ -2170,71 +2174,12 @@ import java.util.Locale; + " ADD " + RawContacts.NAME_VERIFIED + " INTEGER NOT NULL DEFAULT 0;"); } - private interface Organization300Query { - String TABLE = Tables.DATA; - - String SELECTION = DataColumns.MIMETYPE_ID + "=?"; - - String COLUMNS[] = { - Organization._ID, - Organization.RAW_CONTACT_ID, - Organization.COMPANY, - Organization.TITLE - }; - - int ID = 0; - int RAW_CONTACT_ID = 1; - int COMPANY = 2; - int TITLE = 3; - } - /** * Fix for the bug where name lookup records for organizations would get removed by * unrelated updates of the data rows. */ private void upgradeToVersion300(SQLiteDatabase db) { - final long mimeType = lookupMimeTypeId(db, Organization.CONTENT_ITEM_TYPE); - if (mimeType == -1) { - return; - } - - ContentValues values = new ContentValues(); - - // Find all data rows with the mime type "organization" - Cursor cursor = db.query(Organization300Query.TABLE, Organization300Query.COLUMNS, - Organization300Query.SELECTION, new String[] {String.valueOf(mimeType)}, - null, null, null); - try { - while (cursor.moveToNext()) { - long dataId = cursor.getLong(Organization300Query.ID); - long rawContactId = cursor.getLong(Organization300Query.RAW_CONTACT_ID); - String company = cursor.getString(Organization300Query.COMPANY); - String title = cursor.getString(Organization300Query.TITLE); - - // First delete name lookup if there is any (chances are there won't be) - db.delete(Tables.NAME_LOOKUP, NameLookupColumns.DATA_ID + "=?", - new String[]{String.valueOf(dataId)}); - - // Now insert two name lookup records: one for company name, one for title - values.put(NameLookupColumns.DATA_ID, dataId); - values.put(NameLookupColumns.RAW_CONTACT_ID, rawContactId); - values.put(NameLookupColumns.NAME_TYPE, NameLookupType.ORGANIZATION); - - if (!TextUtils.isEmpty(company)) { - values.put(NameLookupColumns.NORMALIZED_NAME, - NameNormalizer.normalize(company)); - db.insert(Tables.NAME_LOOKUP, null, values); - } - - if (!TextUtils.isEmpty(title)) { - values.put(NameLookupColumns.NORMALIZED_NAME, - NameNormalizer.normalize(title)); - db.insert(Tables.NAME_LOOKUP, null, values); - } - } - } finally { - cursor.close(); - } + // No longer needed } private static final class Upgrade303Query { @@ -2475,7 +2420,6 @@ import java.util.Locale; try { insertStructuredNameLookup(db, nameLookupInsert); - insertOrganizationLookup(db, nameLookupInsert); insertEmailLookup(db, nameLookupInsert); insertNicknameLookup(db, nameLookupInsert); } finally { @@ -2571,30 +2515,6 @@ import java.util.Locale; public static final int TITLE = 3; } - /** - * Inserts name lookup rows for all organizations in the database. - */ - private void insertOrganizationLookup(SQLiteDatabase db, SQLiteStatement nameLookupInsert) { - final long mimeTypeId = lookupMimeTypeId(db, Organization.CONTENT_ITEM_TYPE); - Cursor cursor = db.query(OrganizationQuery.TABLE, OrganizationQuery.COLUMNS, - OrganizationQuery.SELECTION, new String[] {String.valueOf(mimeTypeId)}, - null, null, null); - try { - while (cursor.moveToNext()) { - long dataId = cursor.getLong(OrganizationQuery.ID); - long rawContactId = cursor.getLong(OrganizationQuery.RAW_CONTACT_ID); - String organization = cursor.getString(OrganizationQuery.COMPANY); - String title = cursor.getString(OrganizationQuery.TITLE); - insertNameLookup(nameLookupInsert, rawContactId, dataId, - NameLookupType.ORGANIZATION, organization); - insertNameLookup(nameLookupInsert, rawContactId, dataId, - NameLookupType.ORGANIZATION, title); - } - } finally { - cursor.close(); - } - } - private static final class EmailQuery { public static final String TABLE = Tables.DATA; @@ -2876,7 +2796,13 @@ import java.util.Locale; } private void upgradeToVersion500(SQLiteDatabase db) { - createSearchIndexTable(db); + setProperty(db, SearchIndexManager.PROPERTY_SEARCH_INDEX_VERSION, "0"); + } + + private void upgradeToVersion501(SQLiteDatabase db) { + // Remove organization rows from the name lookup, we now use search index for that + db.execSQL("DELETE FROM name_lookup WHERE name_type=5"); + setProperty(db, SearchIndexManager.PROPERTY_SEARCH_INDEX_VERSION, "0"); } public String extractHandleFromEmailAddress(String email) { @@ -3949,18 +3875,6 @@ import java.util.Locale; mNameLookupDelete.execute(); } - public void insertNameLookupForOrganization(long rawContactId, long dataId, String company, - String title) { - if (!TextUtils.isEmpty(company)) { - insertNameLookup(rawContactId, dataId, - NameLookupType.ORGANIZATION, NameNormalizer.normalize(company)); - } - if (!TextUtils.isEmpty(title)) { - insertNameLookup(rawContactId, dataId, - NameLookupType.ORGANIZATION, NameNormalizer.normalize(title)); - } - } - public String insertNameLookupForEmail(long rawContactId, long dataId, String email) { if (TextUtils.isEmpty(email)) { return null; diff --git a/src/com/android/providers/contacts/ContactsProvider2.java b/src/com/android/providers/contacts/ContactsProvider2.java index 1e433ae..e281ba7 100644 --- a/src/com/android/providers/contacts/ContactsProvider2.java +++ b/src/com/android/providers/contacts/ContactsProvider2.java @@ -419,7 +419,6 @@ public class ContactsProvider2 extends SQLiteContentProvider implements OnAccoun NameLookupType.EMAIL_BASED_NICKNAME + "," + NameLookupType.NICKNAME + "," + NameLookupType.NAME_SHORTHAND + "," + - NameLookupType.ORGANIZATION + "," + NameLookupType.NAME_CONSONANTS; /** @@ -5051,7 +5050,6 @@ public class ContactsProvider2 extends SQLiteContentProvider implements OnAccoun + NameLookupType.NAME_COLLATION_KEY + "," + NameLookupType.NICKNAME + "," + NameLookupType.NAME_SHORTHAND + "," - + NameLookupType.ORGANIZATION + "," + NameLookupType.NAME_CONSONANTS); if (allowEmailMatch) { sb.append("," + NameLookupType.EMAIL_BASED_NICKNAME); diff --git a/src/com/android/providers/contacts/DataRowHandlerForOrganization.java b/src/com/android/providers/contacts/DataRowHandlerForOrganization.java index 9d2bce9..0280c3b 100644 --- a/src/com/android/providers/contacts/DataRowHandlerForOrganization.java +++ b/src/com/android/providers/contacts/DataRowHandlerForOrganization.java @@ -46,7 +46,6 @@ public class DataRowHandlerForOrganization extends DataRowHandlerForCommonDataKi long dataId = super.insert(db, txContext, rawContactId, values); fixRawContactDisplayName(db, txContext, rawContactId); - mDbHelper.insertNameLookupForOrganization(rawContactId, dataId, company, title); return dataId; } @@ -87,8 +86,6 @@ public class DataRowHandlerForOrganization extends DataRowHandlerForCommonDataKi } mDbHelper.deleteNameLookup(dataId); - mDbHelper.insertNameLookupForOrganization(rawContactId, dataId, company, title); - fixRawContactDisplayName(db, txContext, rawContactId); } return true; diff --git a/src/com/android/providers/contacts/SearchIndexManager.java b/src/com/android/providers/contacts/SearchIndexManager.java index b36963a..503e66b 100644 --- a/src/com/android/providers/contacts/SearchIndexManager.java +++ b/src/com/android/providers/contacts/SearchIndexManager.java @@ -24,6 +24,10 @@ import android.content.ContentValues; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.os.SystemClock; +import android.provider.ContactsContract.CommonDataKinds.Email; +import android.provider.ContactsContract.CommonDataKinds.Nickname; +import android.provider.ContactsContract.CommonDataKinds.Organization; +import android.provider.ContactsContract.CommonDataKinds.StructuredPostal; import android.provider.ContactsContract.Contacts; import android.provider.ContactsContract.Data; import android.provider.ContactsContract.ProviderStatus; @@ -40,7 +44,7 @@ import java.util.Set; public class SearchIndexManager { private static final String TAG = "ContactsFTS"; - private static final String PROPERTY_SEARCH_INDEX_VERSION = "search_index"; + public static final String PROPERTY_SEARCH_INDEX_VERSION = "search_index"; private static final int SEARCH_INDEX_VERSION = 1; private static final class ContactIndexQuery { @@ -250,11 +254,25 @@ public class SearchIndexManager { } private int buildIndex(SQLiteDatabase db, String selection, boolean replace) { + mSb.setLength(0); + mSb.append(Data.CONTACT_ID + ", "); + mSb.append("(CASE WHEN " + DataColumns.MIMETYPE_ID + "="); + mSb.append(mDbHelper.getMimeTypeId(Nickname.CONTENT_ITEM_TYPE)); + mSb.append(" THEN -4 "); + mSb.append(" WHEN " + DataColumns.MIMETYPE_ID + "="); + mSb.append(mDbHelper.getMimeTypeId(Organization.CONTENT_ITEM_TYPE)); + mSb.append(" THEN -3 "); + mSb.append(" WHEN " + DataColumns.MIMETYPE_ID + "="); + mSb.append(mDbHelper.getMimeTypeId(StructuredPostal.CONTENT_ITEM_TYPE)); + mSb.append(" THEN -2"); + mSb.append(" WHEN " + DataColumns.MIMETYPE_ID + "="); + mSb.append(mDbHelper.getMimeTypeId(Email.CONTENT_ITEM_TYPE)); + mSb.append(" THEN -1"); + mSb.append(" END), " + Data.IS_SUPER_PRIMARY + ", " + DataColumns.CONCRETE_ID); + int count = 0; - Cursor cursor = db.query(Tables.DATA_JOIN_MIMETYPE_RAW_CONTACTS, - ContactIndexQuery.COLUMNS, selection, null, null, null, - Data.CONTACT_ID + ", " + DataColumns.MIMETYPE_ID + ", " + Data.IS_SUPER_PRIMARY - + ", " + DataColumns.CONCRETE_ID); + Cursor cursor = db.query(Tables.DATA_JOIN_MIMETYPE_RAW_CONTACTS, ContactIndexQuery.COLUMNS, + selection, null, null, null, mSb.toString()); mIndexBuilder.setCursor(cursor); mIndexBuilder.reset(); try { |