only search text messages
This commit is contained in:
parent
438ae34988
commit
2505ac8b77
|
@ -725,7 +725,7 @@ public class DatabaseBackend extends SQLiteOpenHelper {
|
||||||
|
|
||||||
public Cursor getMessageSearchCursor(List<String> term) {
|
public Cursor getMessageSearchCursor(List<String> term) {
|
||||||
SQLiteDatabase db = this.getReadableDatabase();
|
SQLiteDatabase db = this.getReadableDatabase();
|
||||||
String SQL = "SELECT "+Message.TABLENAME+".*,"+Conversation.TABLENAME+'.'+Conversation.CONTACTJID+','+Conversation.TABLENAME+'.'+Conversation.ACCOUNT+','+Conversation.TABLENAME+'.'+Conversation.MODE+" FROM "+Message.TABLENAME +" join "+Conversation.TABLENAME+" on "+Message.TABLENAME+'.'+Message.CONVERSATION+'='+Conversation.TABLENAME+'.'+Conversation.UUID+" join messages_index ON messages_index.uuid=messages.uuid where "+Message.ENCRYPTION+" NOT IN("+Message.ENCRYPTION_AXOLOTL_NOT_FOR_THIS_DEVICE+','+Message.ENCRYPTION_PGP+','+Message.ENCRYPTION_DECRYPTION_FAILED+") AND messages_index.body MATCH ? ORDER BY "+Message.TIME_SENT+" DESC limit "+Config.MAX_SEARCH_RESULTS;
|
String SQL = "SELECT "+Message.TABLENAME+".*,"+Conversation.TABLENAME+'.'+Conversation.CONTACTJID+','+Conversation.TABLENAME+'.'+Conversation.ACCOUNT+','+Conversation.TABLENAME+'.'+Conversation.MODE+" FROM "+Message.TABLENAME +" join "+Conversation.TABLENAME+" on "+Message.TABLENAME+'.'+Message.CONVERSATION+'='+Conversation.TABLENAME+'.'+Conversation.UUID+" join messages_index ON messages_index.uuid=messages.uuid where "+Message.ENCRYPTION+" NOT IN("+Message.ENCRYPTION_AXOLOTL_NOT_FOR_THIS_DEVICE+','+Message.ENCRYPTION_PGP+','+Message.ENCRYPTION_DECRYPTION_FAILED+") AND "+Message.TYPE+" IN("+Message.TYPE_TEXT+','+Message.TYPE_PRIVATE+") AND messages_index.body MATCH ? ORDER BY "+Message.TIME_SENT+" DESC limit "+Config.MAX_SEARCH_RESULTS;
|
||||||
Log.d(Config.LOGTAG,"search term: "+FtsUtils.toMatchString(term));
|
Log.d(Config.LOGTAG,"search term: "+FtsUtils.toMatchString(term));
|
||||||
return db.rawQuery(SQL,new String[]{FtsUtils.toMatchString(term)});
|
return db.rawQuery(SQL,new String[]{FtsUtils.toMatchString(term)});
|
||||||
}
|
}
|
||||||
|
|
|
@ -87,6 +87,7 @@ public class MessageSearchTask implements Runnable, Cancellable {
|
||||||
final HashMap<String, Conversational> conversationCache = new HashMap<>();
|
final HashMap<String, Conversational> conversationCache = new HashMap<>();
|
||||||
final List<Message> result = new ArrayList<>();
|
final List<Message> result = new ArrayList<>();
|
||||||
cursor = xmppConnectionService.databaseBackend.getMessageSearchCursor(term);
|
cursor = xmppConnectionService.databaseBackend.getMessageSearchCursor(term);
|
||||||
|
long dbTimer = SystemClock.elapsedRealtime();
|
||||||
if (isCancelled) {
|
if (isCancelled) {
|
||||||
Log.d(Config.LOGTAG, "canceled search task");
|
Log.d(Config.LOGTAG, "canceled search task");
|
||||||
return;
|
return;
|
||||||
|
@ -99,10 +100,8 @@ public class MessageSearchTask implements Runnable, Cancellable {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final String conversationUuid = cursor.getString(cursor.getColumnIndex(Message.CONVERSATION));
|
final String conversationUuid = cursor.getString(cursor.getColumnIndex(Message.CONVERSATION));
|
||||||
Conversational conversation;
|
Conversational conversation = conversationCache.get(conversationUuid);
|
||||||
if (conversationCache.containsKey(conversationUuid)) {
|
if (conversation == null) {
|
||||||
conversation = conversationCache.get(conversationUuid);
|
|
||||||
} else {
|
|
||||||
String accountUuid = cursor.getString(cursor.getColumnIndex(Conversation.ACCOUNT));
|
String accountUuid = cursor.getString(cursor.getColumnIndex(Conversation.ACCOUNT));
|
||||||
String contactJid = cursor.getString(cursor.getColumnIndex(Conversation.CONTACTJID));
|
String contactJid = cursor.getString(cursor.getColumnIndex(Conversation.CONTACTJID));
|
||||||
int mode = cursor.getInt(cursor.getColumnIndex(Conversation.MODE));
|
int mode = cursor.getInt(cursor.getColumnIndex(Conversation.MODE));
|
||||||
|
@ -114,7 +113,7 @@ public class MessageSearchTask implements Runnable, Cancellable {
|
||||||
} while (cursor.moveToPrevious());
|
} while (cursor.moveToPrevious());
|
||||||
}
|
}
|
||||||
long stopTimestamp = SystemClock.elapsedRealtime();
|
long stopTimestamp = SystemClock.elapsedRealtime();
|
||||||
Log.d(Config.LOGTAG, "found " + result.size() + " messages in " + (stopTimestamp - startTimestamp) + "ms");
|
Log.d(Config.LOGTAG, "found " + result.size() + " messages in " + (stopTimestamp - startTimestamp) + "ms"+ " (db was "+(dbTimer - startTimestamp)+"ms)");
|
||||||
onSearchResultsAvailable.onSearchResultsAvailable(term, result);
|
onSearchResultsAvailable.onSearchResultsAvailable(term, result);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.d(Config.LOGTAG, "exception while searching ", e);
|
Log.d(Config.LOGTAG, "exception while searching ", e);
|
||||||
|
|
|
@ -46,7 +46,7 @@ public class FtsUtils {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
final String cleaned = clean(part);
|
final String cleaned = clean(part);
|
||||||
if (isKeyword(cleaned)) {
|
if (isKeyword(cleaned) || cleaned.contains("*")) {
|
||||||
term.add(part);
|
term.add(part);
|
||||||
} else if (!cleaned.isEmpty()) {
|
} else if (!cleaned.isEmpty()) {
|
||||||
term.add(cleaned);
|
term.add(cleaned);
|
||||||
|
@ -72,7 +72,7 @@ public class FtsUtils {
|
||||||
return builder.toString();
|
return builder.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isKeyword(String term) {
|
static boolean isKeyword(String term) {
|
||||||
return KEYWORDS.contains(term.toUpperCase(Locale.ENGLISH));
|
return KEYWORDS.contains(term.toUpperCase(Locale.ENGLISH));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue