Remove duplicates into Search results
In schema version 100, we were using data_title and data_summary for storing a normalized version of the title and summary. This was leading to have duplicate results. Now (in schema version 101), we are introducing two new colums for storing normalized title and summary. We are also doing a new MATCH query on those two new columns and that fixes the duplicates issue. Change-Id: I609675cdd1a47a1a29595f0fe8b87ad96c6e4522
This commit is contained in:
@@ -28,7 +28,7 @@ public class IndexDatabaseHelper extends SQLiteOpenHelper {
|
||||
private static final String TAG = "IndexDatabaseHelper";
|
||||
|
||||
private static final String DATABASE_NAME = "search_index.db";
|
||||
private static final int DATABASE_VERSION = 100;
|
||||
private static final int DATABASE_VERSION = 101;
|
||||
|
||||
public interface Tables {
|
||||
public static final String TABLE_PREFS_INDEX = "prefs_index";
|
||||
@@ -39,7 +39,9 @@ public class IndexDatabaseHelper extends SQLiteOpenHelper {
|
||||
public static final String LOCALE = "locale";
|
||||
public static final String DATA_RANK = "data_rank";
|
||||
public static final String DATA_TITLE = "data_title";
|
||||
public static final String DATA_TITLE_NORMALIZED = "data_title_normalized";
|
||||
public static final String DATA_SUMMARY = "data_summary";
|
||||
public static final String DATA_SUMMARY_NORMALIZED = "data_summary_normalized";
|
||||
public static final String DATA_KEYWORDS = "data_keywords";
|
||||
public static final String FRAGMENT_NAME = "fragment_name";
|
||||
public static final String FRAGMENT_TITLE = "fragment_title";
|
||||
@@ -60,8 +62,12 @@ public class IndexDatabaseHelper extends SQLiteOpenHelper {
|
||||
", " +
|
||||
IndexColumns.DATA_TITLE +
|
||||
", " +
|
||||
IndexColumns.DATA_TITLE_NORMALIZED +
|
||||
", " +
|
||||
IndexColumns.DATA_SUMMARY +
|
||||
", " +
|
||||
IndexColumns.DATA_SUMMARY_NORMALIZED +
|
||||
", " +
|
||||
IndexColumns.DATA_KEYWORDS +
|
||||
", " +
|
||||
IndexColumns.FRAGMENT_NAME +
|
||||
@@ -113,6 +119,13 @@ public class IndexDatabaseHelper extends SQLiteOpenHelper {
|
||||
|
||||
@Override
|
||||
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
|
||||
if (newVersion > 100) {
|
||||
Log.w(TAG, "Detected schema version 100. " +
|
||||
"Index needs to be rebuilt for schema version 101");
|
||||
// We need to drop the tables and recreate them
|
||||
dropTables(db);
|
||||
bootstrapDB(db);
|
||||
}
|
||||
}
|
||||
|
||||
private String getBuildVersion(SQLiteDatabase db) {
|
||||
@@ -144,8 +157,10 @@ public class IndexDatabaseHelper extends SQLiteOpenHelper {
|
||||
public void onOpen(SQLiteDatabase db) {
|
||||
super.onOpen(db);
|
||||
|
||||
Log.i(TAG, "Using schema version: " + db.getVersion());
|
||||
|
||||
if (!Build.VERSION.INCREMENTAL.equals(getBuildVersion(db))) {
|
||||
Log.w(TAG, "Index needs to be rebuilt");
|
||||
Log.w(TAG, "Index needs to be rebuilt as build-version is not the same");
|
||||
// We need to drop the tables and recreate them
|
||||
dropTables(db);
|
||||
bootstrapDB(db);
|
||||
|
||||
Reference in New Issue
Block a user