From b58b28e13e2771cbe5dc102488cdd86dea14e5b2 Mon Sep 17 00:00:00 2001 From: Fabrice Di Meglio Date: Tue, 20 May 2014 16:31:52 -0700 Subject: [PATCH] Fix bug #14494292 Settings>Search>Recent searches keep on populating the same keyword if it is searched again - do the right thing: remove the previous search queries from the Database if needed so that there will be no dupe Change-Id: I707eb518ea7c2a64b1407c62ff164e249fe03fa9 --- src/com/android/settings/search/Index.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/com/android/settings/search/Index.java b/src/com/android/settings/search/Index.java index 1bcb9d86faa..adddb399549 100644 --- a/src/com/android/settings/search/Index.java +++ b/src/com/android/settings/search/Index.java @@ -1217,9 +1217,16 @@ public class Index { long lastInsertedRowId = -1; try { - lastInsertedRowId = - database.replaceOrThrow(Tables.TABLE_SAVED_QUERIES, null, values); + // First, delete all saved queries that are the same + database.delete(Tables.TABLE_SAVED_QUERIES, + IndexDatabaseHelper.SavedQueriesColums.QUERY + " = ?", + new String[] { params[0] }); + // Second, insert the saved query + lastInsertedRowId = + database.insertOrThrow(Tables.TABLE_SAVED_QUERIES, null, values); + + // Last, remove "old" saved queries final long delta = lastInsertedRowId - MAX_SAVED_SEARCH_QUERY; if (delta > 0) { int count = database.delete(Tables.TABLE_SAVED_QUERIES, "rowId <= ?",