Search - add support for deleting all preferences for a class name

- modify SQL delete query for passing any column in the DELETE statement
- modify deleteIndexableData(...) for passing a SearchIndexableData

Change-Id: I4c58e38422e67b1d464b0e51201520ce8717a14d
This commit is contained in:
Fabrice Di Meglio
2014-04-14 11:24:16 -07:00
parent df278aa959
commit 724b702a86

View File

@@ -152,14 +152,14 @@ public class Index {
*/ */
private class UpdateData { private class UpdateData {
public List<SearchIndexableData> dataToUpdate; public List<SearchIndexableData> dataToUpdate;
public List<String> dataToDelete; public List<SearchIndexableData> dataToDelete;
public Map<String, List<String>> nonIndexableKeys; public Map<String, List<String>> nonIndexableKeys;
public boolean forceUpdate = false; public boolean forceUpdate = false;
public UpdateData() { public UpdateData() {
dataToUpdate = new ArrayList<SearchIndexableData>(); dataToUpdate = new ArrayList<SearchIndexableData>();
dataToDelete = new ArrayList<String>(); dataToDelete = new ArrayList<SearchIndexableData>();
nonIndexableKeys = new HashMap<String, List<String>>(); nonIndexableKeys = new HashMap<String, List<String>>();
} }
@@ -304,12 +304,9 @@ public class Index {
} }
} }
public void deleteIndexableData(String[] array) { public void deleteIndexableData(SearchIndexableData data) {
synchronized (mDataToProcess) { synchronized (mDataToProcess) {
final int count = array.length; mDataToProcess.dataToDelete.add(data);
for (int n = 0; n < count; n++) {
mDataToProcess.dataToDelete.add(array[n]);
}
} }
} }
@@ -1022,7 +1019,7 @@ public class Index {
boolean result = false; boolean result = false;
final List<SearchIndexableData> dataToUpdate = params[0].dataToUpdate; final List<SearchIndexableData> dataToUpdate = params[0].dataToUpdate;
final List<String> dataToDelete = params[0].dataToDelete; final List<SearchIndexableData> dataToDelete = params[0].dataToDelete;
final Map<String, List<String>> nonIndexableKeys = params[0].nonIndexableKeys; final Map<String, List<String>> nonIndexableKeys = params[0].nonIndexableKeys;
final boolean forceUpdate = params[0].forceUpdate; final boolean forceUpdate = params[0].forceUpdate;
@@ -1072,15 +1069,27 @@ public class Index {
} }
private boolean processDataToDelete(SQLiteDatabase database, String localeStr, private boolean processDataToDelete(SQLiteDatabase database, String localeStr,
List<String> dataToDelete) { List<SearchIndexableData> dataToDelete) {
boolean result = false; boolean result = false;
final long current = System.currentTimeMillis(); final long current = System.currentTimeMillis();
final int count = dataToDelete.size(); final int count = dataToDelete.size();
for (int n = 0; n < count; n++) { for (int n = 0; n < count; n++) {
final String data = dataToDelete.get(n); final SearchIndexableData data = dataToDelete.get(n);
delete(database, data); if (data == null) {
continue;
}
if (!TextUtils.isEmpty(data.className)) {
delete(database, IndexColumns.CLASS_NAME, data.className);
} else {
if (data instanceof SearchIndexableRaw) {
final SearchIndexableRaw raw = (SearchIndexableRaw) data;
if (!TextUtils.isEmpty(raw.title)) {
delete(database, IndexColumns.DATA_TITLE, raw.title);
}
}
}
} }
final long now = System.currentTimeMillis(); final long now = System.currentTimeMillis();
@@ -1089,9 +1098,9 @@ public class Index {
return result; return result;
} }
private int delete(SQLiteDatabase database, String title) { private int delete(SQLiteDatabase database, String columName, String value) {
final String whereClause = IndexColumns.DATA_TITLE + "=?"; final String whereClause = columName + "=?";
final String[] whereArgs = new String[] { title }; final String[] whereArgs = new String[] { value };
return database.delete(Tables.TABLE_PREFS_INDEX, whereClause, whereArgs); return database.delete(Tables.TABLE_PREFS_INDEX, whereClause, whereArgs);
} }