Merge "Fix search after upgrade" into nyc-dev
am: f96b594
* commit 'f96b5947f9122e471d7cc72847f707bc4dcc30a4':
Fix search after upgrade
Change-Id: Iba0908e1a338fc4feea5ce6c7fbbe5847cd16dcb
This commit is contained in:
@@ -140,7 +140,6 @@ public class Index {
|
|||||||
IndexColumns.DATA_SUMMARY_OFF_NORMALIZED,
|
IndexColumns.DATA_SUMMARY_OFF_NORMALIZED,
|
||||||
IndexColumns.DATA_ENTRIES
|
IndexColumns.DATA_ENTRIES
|
||||||
};
|
};
|
||||||
private static final String INDEX = "index";
|
|
||||||
|
|
||||||
// Max number of saved search queries (who will be used for proposing suggestions)
|
// Max number of saved search queries (who will be used for proposing suggestions)
|
||||||
private static long MAX_SAVED_SEARCH_QUERY = 64;
|
private static long MAX_SAVED_SEARCH_QUERY = 64;
|
||||||
@@ -1223,7 +1222,7 @@ public class Index {
|
|||||||
database.endTransaction();
|
database.endTransaction();
|
||||||
}
|
}
|
||||||
if (fullIndex) {
|
if (fullIndex) {
|
||||||
setLocaleIndexed(localeStr);
|
IndexDatabaseHelper.setLocaleIndexed(mContext, localeStr);
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
@@ -1233,7 +1232,7 @@ public class Index {
|
|||||||
List<SearchIndexableData> dataToUpdate, Map<String, List<String>> nonIndexableKeys,
|
List<SearchIndexableData> dataToUpdate, Map<String, List<String>> nonIndexableKeys,
|
||||||
boolean forceUpdate) {
|
boolean forceUpdate) {
|
||||||
|
|
||||||
if (!forceUpdate && isLocaleAlreadyIndexed(database, localeStr)) {
|
if (!forceUpdate && IndexDatabaseHelper.isLocaleAlreadyIndexed(mContext, localeStr)) {
|
||||||
Log.d(LOG_TAG, "Locale '" + localeStr + "' is already indexed");
|
Log.d(LOG_TAG, "Locale '" + localeStr + "' is already indexed");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -1294,14 +1293,6 @@ public class Index {
|
|||||||
|
|
||||||
return database.delete(Tables.TABLE_PREFS_INDEX, whereClause, whereArgs);
|
return database.delete(Tables.TABLE_PREFS_INDEX, whereClause, whereArgs);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setLocaleIndexed(String locale) {
|
|
||||||
mContext.getSharedPreferences(INDEX, 0).edit().putBoolean(locale, true).commit();
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isLocaleAlreadyIndexed(SQLiteDatabase database, String locale) {
|
|
||||||
return mContext.getSharedPreferences(INDEX, 0).getBoolean(locale, false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -30,6 +30,8 @@ public class IndexDatabaseHelper extends SQLiteOpenHelper {
|
|||||||
private static final String DATABASE_NAME = "search_index.db";
|
private static final String DATABASE_NAME = "search_index.db";
|
||||||
private static final int DATABASE_VERSION = 115;
|
private static final int DATABASE_VERSION = 115;
|
||||||
|
|
||||||
|
private static final String INDEX = "index";
|
||||||
|
|
||||||
public interface Tables {
|
public interface Tables {
|
||||||
public static final String TABLE_PREFS_INDEX = "prefs_index";
|
public static final String TABLE_PREFS_INDEX = "prefs_index";
|
||||||
public static final String TABLE_META_INDEX = "meta_index";
|
public static final String TABLE_META_INDEX = "meta_index";
|
||||||
@@ -63,7 +65,7 @@ public class IndexDatabaseHelper extends SQLiteOpenHelper {
|
|||||||
public static final String BUILD = "build";
|
public static final String BUILD = "build";
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface SavedQueriesColums {
|
public interface SavedQueriesColums {
|
||||||
public static final String QUERY = "query";
|
public static final String QUERY = "query";
|
||||||
public static final String TIME_STAMP = "timestamp";
|
public static final String TIME_STAMP = "timestamp";
|
||||||
}
|
}
|
||||||
@@ -133,6 +135,8 @@ public class IndexDatabaseHelper extends SQLiteOpenHelper {
|
|||||||
|
|
||||||
private static IndexDatabaseHelper sSingleton;
|
private static IndexDatabaseHelper sSingleton;
|
||||||
|
|
||||||
|
private final Context mContext;
|
||||||
|
|
||||||
public static synchronized IndexDatabaseHelper getInstance(Context context) {
|
public static synchronized IndexDatabaseHelper getInstance(Context context) {
|
||||||
if (sSingleton == null) {
|
if (sSingleton == null) {
|
||||||
sSingleton = new IndexDatabaseHelper(context);
|
sSingleton = new IndexDatabaseHelper(context);
|
||||||
@@ -142,6 +146,7 @@ public class IndexDatabaseHelper extends SQLiteOpenHelper {
|
|||||||
|
|
||||||
public IndexDatabaseHelper(Context context) {
|
public IndexDatabaseHelper(Context context) {
|
||||||
super(context, DATABASE_NAME, null, DATABASE_VERSION);
|
super(context, DATABASE_NAME, null, DATABASE_VERSION);
|
||||||
|
mContext = context;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -175,7 +180,7 @@ public class IndexDatabaseHelper extends SQLiteOpenHelper {
|
|||||||
@Override
|
@Override
|
||||||
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
|
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
|
||||||
if (oldVersion < DATABASE_VERSION) {
|
if (oldVersion < DATABASE_VERSION) {
|
||||||
Log.w(TAG, "Detected schema version '" + oldVersion + "'. " +
|
Log.w(TAG, "Detected schema version '" + oldVersion + "'. " +
|
||||||
"Index needs to be rebuilt for schema version '" + newVersion + "'.");
|
"Index needs to be rebuilt for schema version '" + newVersion + "'.");
|
||||||
// We need to drop the tables and recreate them
|
// We need to drop the tables and recreate them
|
||||||
reconstruct(db);
|
reconstruct(db);
|
||||||
@@ -184,7 +189,7 @@ public class IndexDatabaseHelper extends SQLiteOpenHelper {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) {
|
public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) {
|
||||||
Log.w(TAG, "Detected schema version '" + oldVersion + "'. " +
|
Log.w(TAG, "Detected schema version '" + oldVersion + "'. " +
|
||||||
"Index needs to be rebuilt for schema version '" + newVersion + "'.");
|
"Index needs to be rebuilt for schema version '" + newVersion + "'.");
|
||||||
// We need to drop the tables and recreate them
|
// We need to drop the tables and recreate them
|
||||||
reconstruct(db);
|
reconstruct(db);
|
||||||
@@ -203,11 +208,9 @@ public class IndexDatabaseHelper extends SQLiteOpenHelper {
|
|||||||
if (cursor.moveToFirst()) {
|
if (cursor.moveToFirst()) {
|
||||||
version = cursor.getString(0);
|
version = cursor.getString(0);
|
||||||
}
|
}
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch (Exception e) {
|
|
||||||
Log.e(TAG, "Cannot get build version from Index metadata");
|
Log.e(TAG, "Cannot get build version from Index metadata");
|
||||||
}
|
} finally {
|
||||||
finally {
|
|
||||||
if (cursor != null) {
|
if (cursor != null) {
|
||||||
cursor.close();
|
cursor.close();
|
||||||
}
|
}
|
||||||
@@ -215,7 +218,20 @@ public class IndexDatabaseHelper extends SQLiteOpenHelper {
|
|||||||
return version;
|
return version;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void clearLocalesIndexed(Context context) {
|
||||||
|
context.getSharedPreferences(INDEX, 0).edit().clear().commit();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setLocaleIndexed(Context context, String locale) {
|
||||||
|
context.getSharedPreferences(INDEX, 0).edit().putBoolean(locale, true).commit();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isLocaleAlreadyIndexed(Context context, String locale) {
|
||||||
|
return context.getSharedPreferences(INDEX, 0).getBoolean(locale, false);
|
||||||
|
}
|
||||||
|
|
||||||
private void dropTables(SQLiteDatabase db) {
|
private void dropTables(SQLiteDatabase db) {
|
||||||
|
clearLocalesIndexed(mContext);
|
||||||
db.execSQL("DROP TABLE IF EXISTS " + Tables.TABLE_META_INDEX);
|
db.execSQL("DROP TABLE IF EXISTS " + Tables.TABLE_META_INDEX);
|
||||||
db.execSQL("DROP TABLE IF EXISTS " + Tables.TABLE_PREFS_INDEX);
|
db.execSQL("DROP TABLE IF EXISTS " + Tables.TABLE_PREFS_INDEX);
|
||||||
db.execSQL("DROP TABLE IF EXISTS " + Tables.TABLE_SAVED_QUERIES);
|
db.execSQL("DROP TABLE IF EXISTS " + Tables.TABLE_SAVED_QUERIES);
|
||||||
|
Reference in New Issue
Block a user