From 553755d757b381b047b702f715247f2e50b03c4a Mon Sep 17 00:00:00 2001 From: Christian Schneppe Date: Wed, 2 May 2018 21:53:40 +0200 Subject: only search text messages --- .../java/de/pixart/messenger/persistance/DatabaseBackend.java | 2 +- .../java/de/pixart/messenger/services/MessageSearchTask.java | 9 ++++----- src/main/java/de/pixart/messenger/utils/FtsUtils.java | 4 ++-- 3 files changed, 7 insertions(+), 8 deletions(-) (limited to 'src/main/java/de') diff --git a/src/main/java/de/pixart/messenger/persistance/DatabaseBackend.java b/src/main/java/de/pixart/messenger/persistance/DatabaseBackend.java index b7973aca6..7d9c38718 100644 --- a/src/main/java/de/pixart/messenger/persistance/DatabaseBackend.java +++ b/src/main/java/de/pixart/messenger/persistance/DatabaseBackend.java @@ -738,7 +738,7 @@ public class DatabaseBackend extends SQLiteOpenHelper { public Cursor getMessageSearchCursor(List term) { 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)); return db.rawQuery(SQL, new String[]{FtsUtils.toMatchString(term)}); } diff --git a/src/main/java/de/pixart/messenger/services/MessageSearchTask.java b/src/main/java/de/pixart/messenger/services/MessageSearchTask.java index 76c3800d2..1b10daa32 100644 --- a/src/main/java/de/pixart/messenger/services/MessageSearchTask.java +++ b/src/main/java/de/pixart/messenger/services/MessageSearchTask.java @@ -86,6 +86,7 @@ public class MessageSearchTask implements Runnable, Cancellable { final HashMap conversationCache = new HashMap<>(); final List result = new ArrayList<>(); cursor = xmppConnectionService.databaseBackend.getMessageSearchCursor(term); + long dbTimer = SystemClock.elapsedRealtime(); if (isCancelled) { Log.d(Config.LOGTAG, "canceled search task"); return; @@ -98,10 +99,8 @@ public class MessageSearchTask implements Runnable, Cancellable { return; } final String conversationUuid = cursor.getString(cursor.getColumnIndex(Message.CONVERSATION)); - Conversational conversation; - if (conversationCache.containsKey(conversationUuid)) { - conversation = conversationCache.get(conversationUuid); - } else { + Conversational conversation = conversationCache.get(conversationUuid); + if (conversation == null) { String accountUuid = cursor.getString(cursor.getColumnIndex(Conversation.ACCOUNT)); String contactJid = cursor.getString(cursor.getColumnIndex(Conversation.CONTACTJID)); int mode = cursor.getInt(cursor.getColumnIndex(Conversation.MODE)); @@ -113,7 +112,7 @@ public class MessageSearchTask implements Runnable, Cancellable { } while (cursor.moveToPrevious()); } 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); } catch (Exception e) { Log.d(Config.LOGTAG, "exception while searching ", e); diff --git a/src/main/java/de/pixart/messenger/utils/FtsUtils.java b/src/main/java/de/pixart/messenger/utils/FtsUtils.java index c6870d07e..ee4f10da5 100644 --- a/src/main/java/de/pixart/messenger/utils/FtsUtils.java +++ b/src/main/java/de/pixart/messenger/utils/FtsUtils.java @@ -45,7 +45,7 @@ public class FtsUtils { continue; } final String cleaned = clean(part); - if (isKeyword(cleaned)) { + if (isKeyword(cleaned) || cleaned.contains("*")) { term.add(part); } else if (!cleaned.isEmpty()) { term.add(cleaned); @@ -71,7 +71,7 @@ public class FtsUtils { return builder.toString(); } - public static boolean isKeyword(String term) { + static boolean isKeyword(String term) { return KEYWORDS.contains(term.toUpperCase(Locale.ENGLISH)); } -- cgit v1.2.3