From 5f99470226f6a03538313852c2df9e27b3d8ed2e Mon Sep 17 00:00:00 2001 From: Greyson Parrelli Date: Fri, 15 Jun 2018 12:18:39 -0700 Subject: [PATCH] Allow searching for words with apostrophes. Previously, because apostrophes were 'banned' characters, searching for them wouldn't work. That meant you couldn't find words like "I'm". Now we just replace the apostrophe with a space and things "just work" because of the nature of SQLite tokenization and prefix queries. --- src/org/thoughtcrime/securesms/search/SearchRepository.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/org/thoughtcrime/securesms/search/SearchRepository.java b/src/org/thoughtcrime/securesms/search/SearchRepository.java index fb4d0f344d..d837cdc4a0 100644 --- a/src/org/thoughtcrime/securesms/search/SearchRepository.java +++ b/src/org/thoughtcrime/securesms/search/SearchRepository.java @@ -119,6 +119,9 @@ class SearchRepository { /** * Unfortunately {@link DatabaseUtils#sqlEscapeString(String)} is not sufficient for our purposes. * MATCH queries have a separate format of their own that disallow most "special" characters. + * + * Also, SQLite can't search for apostrophes, meaning we can't normally find words like "I'm". + * However, if we replace the apostrophe with a space, then the query will find the match. */ private String sanitizeQuery(@NonNull String query) { StringBuilder out = new StringBuilder(); @@ -127,6 +130,8 @@ class SearchRepository { char c = query.charAt(i); if (!BANNED_CHARACTERS.contains(c)) { out.append(c); + } else if (c == '\'') { + out.append(' '); } }