Skip to content

Commit

Permalink
Make sure the FTS search cursor joins on task ID, not in instance ID. F…
Browse files Browse the repository at this point in the history
…ixes #322
  • Loading branch information
dmfs committed Mar 29, 2017
1 parent 83faf64 commit 4a301e0
Showing 1 changed file with 14 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

/**
* Supports the {@link TaskDatabaseHelper} in the manner of full-text-search.
*
*
* @author Tobias Reinsch <tobias@dmfs.org>
* @author Marten Gajda <marten@dmfs.org>
*/
Expand Down Expand Up @@ -125,8 +125,8 @@ public interface NGramColumns
// FIXME: at present the minimum score is hard coded can we leave that decision to the caller?
private final static String SQL_RAW_QUERY_SEARCH_TASK = "SELECT %s " + ", min(1.0*count(*)/?, 1.0) as " + TaskContract.Tasks.SCORE + " from "
+ FTS_NGRAM_TABLE + " join " + FTS_CONTENT_TABLE + " on (" + FTS_NGRAM_TABLE + "." + NGramColumns.NGRAM_ID + "=" + FTS_CONTENT_TABLE + "."
+ FTSContentColumns.NGRAM_ID + ") join " + Tables.INSTANCE_VIEW + " on (" + Tables.INSTANCE_VIEW + "." + Tasks._ID + " = " + FTS_CONTENT_TABLE + "."
+ FTSContentColumns.TASK_ID + ") where %s group by " + Tasks._ID + " having " + TaskContract.Tasks.SCORE + " >= " + SEARCH_RESULTS_MIN_SCORE
+ FTSContentColumns.NGRAM_ID + ") join " + Tables.INSTANCE_VIEW + " on (" + Tables.INSTANCE_VIEW + "." + TaskContract.Instances.TASK_ID + " = " + FTS_CONTENT_TABLE + "."
+ FTSContentColumns.TASK_ID + ") where %s group by " + TaskContract.Instances.TASK_ID + " having " + TaskContract.Tasks.SCORE + " >= " + SEARCH_RESULTS_MIN_SCORE
+ " order by %s;";

private final static String SQL_RAW_QUERY_SEARCH_TASK_DEFAULT_PROJECTION = Tables.INSTANCE_VIEW + ".* ," + FTS_NGRAM_TABLE + "." + NGramColumns.TEXT;
Expand All @@ -140,7 +140,7 @@ public interface NGramColumns

/**
* The different types of searchable entries for tasks linked to the <code>TYPE</code> column.
*
*
* @author Tobias Reinsch <tobias@dmfs.org>
* @author Marten Gajda <marten@dmfs.org>
*/
Expand Down Expand Up @@ -192,7 +192,7 @@ public static void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)

/**
* Creates the tables and triggers used in FTS.
*
*
* @param db
* The {@link SQLiteDatabase}.
*/
Expand All @@ -218,7 +218,7 @@ private static void initializeFTS(SQLiteDatabase db)

/**
* Creates the FTS entries for the existing tasks.
*
*
* @param db
* The writable {@link SQLiteDatabase}.
*/
Expand All @@ -236,10 +236,10 @@ private static void initializeFTSContent(SQLiteDatabase db)

/**
* Inserts the searchable texts of the task in the database.
*
*
* @param db
* The writable {@link SQLiteDatabase}.
*
*
* @param taskId
* The row id of the task.
* @param title
Expand Down Expand Up @@ -272,7 +272,7 @@ private static void insertTaskFTSEntries(SQLiteDatabase db, long taskId, String

/**
* Updates the existing searchables entries for the task.
*
*
* @param db
* The writable {@link SQLiteDatabase}.
* @param task
Expand Down Expand Up @@ -303,7 +303,7 @@ public static void updateTaskFTSEntries(SQLiteDatabase db, TaskAdapter task)

/**
* Updates or creates the searchable entries for a property. Passing <code>null</code> as searchable text will remove the entry.
*
*
* @param db
* The writable {@link SQLiteDatabase}.
* @param taskId
Expand All @@ -321,7 +321,7 @@ public static void updatePropertyFTSEntry(SQLiteDatabase db, long taskId, long p

/**
* Inserts NGrams into the NGram database.
*
*
* @param db
* A writable {@link SQLiteDatabase}.
* @param ngrams
Expand Down Expand Up @@ -385,7 +385,7 @@ private static void updateEntry(SQLiteDatabase db, long taskId, long propertyId,

/**
* Inserts NGrams relations for a task entry.
*
*
* @param db
* A writable {@link SQLiteDatabase}.
* @param ngramIds
Expand Down Expand Up @@ -421,7 +421,7 @@ private static void insertNGramRelations(SQLiteDatabase db, Set<Long> ngramIds,

/**
* Deletes the NGram relations of a task
*
*
* @param db
* The writable {@link SQLiteDatabase}.
* @param taskId
Expand All @@ -446,7 +446,7 @@ private static int deleteNGramRelations(SQLiteDatabase db, long taskId, long pro

/**
* Queries the task database to get a cursor with the search results.
*
*
* @param db
* The {@link SQLiteDatabase}.
* @param searchString
Expand Down Expand Up @@ -552,7 +552,6 @@ public static Cursor getTaskSearchCursor(SQLiteDatabase db, String searchString,
{
sortOrder = Tasks.SCORE + " desc, " + sortOrder;
}

Cursor c = db.rawQueryWithFactory(null,
String.format(SQL_RAW_QUERY_SEARCH_TASK, SQL_RAW_QUERY_SEARCH_TASK_DEFAULT_PROJECTION, selectionBuilder.toString(), sortOrder), queryArgs, null);
return c;
Expand Down

0 comments on commit 4a301e0

Please sign in to comment.