Use correct recipient for message search results.

Previously, we'd always use the recipient of the message record, which
was incorrect for messages sent to groups. Now we always use the
recipient for the matching thread record.

Fixes #7823
This commit is contained in:
Greyson Parrelli 2018-05-22 12:08:24 -04:00
parent a792a6e6ae
commit e6e8416aec

View File

@ -53,23 +53,25 @@ public class SearchDatabase extends Database {
private static final String MESSAGES_QUERY = private static final String MESSAGES_QUERY =
"SELECT " + "SELECT " +
MmsSmsColumns.ADDRESS + ", " + ThreadDatabase.TABLE_NAME + "." + ThreadDatabase.ADDRESS + ", " +
"snippet(" + SMS_FTS_TABLE_NAME + ", -1, '', '', '...', 7) AS " + SNIPPET + ", " + "snippet(" + SMS_FTS_TABLE_NAME + ", -1, '', '', '...', 7) AS " + SNIPPET + ", " +
SmsDatabase.DATE_RECEIVED + " AS " + MmsSmsColumns.NORMALIZED_DATE_RECEIVED + ", " + SmsDatabase.TABLE_NAME + "." + SmsDatabase.DATE_RECEIVED + " AS " + MmsSmsColumns.NORMALIZED_DATE_RECEIVED + ", " +
MmsSmsColumns.THREAD_ID + ", " + MmsSmsColumns.THREAD_ID + ", " +
"bm25(" + SMS_FTS_TABLE_NAME + ") AS " + RANK + " " + "bm25(" + SMS_FTS_TABLE_NAME + ") AS " + RANK + " " +
"FROM " + SmsDatabase.TABLE_NAME + " " + "FROM " + SmsDatabase.TABLE_NAME + " " +
"INNER JOIN " + SMS_FTS_TABLE_NAME + " ON " + SMS_FTS_TABLE_NAME + "." + ID + " = " + SmsDatabase.TABLE_NAME + "." + SmsDatabase.ID + " " + "INNER JOIN " + SMS_FTS_TABLE_NAME + " ON " + SMS_FTS_TABLE_NAME + "." + ID + " = " + SmsDatabase.TABLE_NAME + "." + SmsDatabase.ID + " " +
"INNER JOIN " + ThreadDatabase.TABLE_NAME + " ON " + SmsDatabase.TABLE_NAME + "." + MmsSmsColumns.THREAD_ID + " = " + ThreadDatabase.TABLE_NAME + "." + ThreadDatabase.ID + " " +
"WHERE " + SMS_FTS_TABLE_NAME + " MATCH ? " + "WHERE " + SMS_FTS_TABLE_NAME + " MATCH ? " +
"UNION ALL " + "UNION ALL " +
"SELECT " + "SELECT " +
MmsSmsColumns.ADDRESS + ", " + ThreadDatabase.TABLE_NAME + "." + ThreadDatabase.ADDRESS + ", " +
"snippet(" + MMS_FTS_TABLE_NAME + ", -1, '', '', '...', 7) AS " + SNIPPET + ", " + "snippet(" + MMS_FTS_TABLE_NAME + ", -1, '', '', '...', 7) AS " + SNIPPET + ", " +
MmsDatabase.DATE_RECEIVED + " AS " + MmsSmsColumns.NORMALIZED_DATE_RECEIVED + ", " + MmsDatabase.TABLE_NAME + "." + MmsDatabase.DATE_RECEIVED + " AS " + MmsSmsColumns.NORMALIZED_DATE_RECEIVED + ", " +
MmsSmsColumns.THREAD_ID + ", " + MmsSmsColumns.THREAD_ID + ", " +
"bm25(" + MMS_FTS_TABLE_NAME + ") AS " + RANK + " " + "bm25(" + MMS_FTS_TABLE_NAME + ") AS " + RANK + " " +
"FROM " + MmsDatabase.TABLE_NAME + " " + "FROM " + MmsDatabase.TABLE_NAME + " " +
"INNER JOIN " + MMS_FTS_TABLE_NAME + " ON " + MMS_FTS_TABLE_NAME + "." + ID + " = " + MmsDatabase.TABLE_NAME + "." + MmsDatabase.ID + " " + "INNER JOIN " + MMS_FTS_TABLE_NAME + " ON " + MMS_FTS_TABLE_NAME + "." + ID + " = " + MmsDatabase.TABLE_NAME + "." + MmsDatabase.ID + " " +
"INNER JOIN " + ThreadDatabase.TABLE_NAME + " ON " + MmsDatabase.TABLE_NAME + "." + MmsSmsColumns.THREAD_ID + " = " + ThreadDatabase.TABLE_NAME + "." + ThreadDatabase.ID + " " +
"WHERE " + MMS_FTS_TABLE_NAME + " MATCH ? " + "WHERE " + MMS_FTS_TABLE_NAME + " MATCH ? " +
"ORDER BY rank " + "ORDER BY rank " +
"LIMIT 500"; "LIMIT 500";