From 755d30254efe8272899e92d14ae6c2748514de62 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Thu, 14 Jun 2018 13:08:44 -0400 Subject: [PATCH] Improve search query construction. --- .../src/Storage/FullTextSearchFinder.swift | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/SignalServiceKit/src/Storage/FullTextSearchFinder.swift b/SignalServiceKit/src/Storage/FullTextSearchFinder.swift index bb35d8f52..67e311816 100644 --- a/SignalServiceKit/src/Storage/FullTextSearchFinder.swift +++ b/SignalServiceKit/src/Storage/FullTextSearchFinder.swift @@ -52,7 +52,9 @@ public class FullTextSearchFinder: NSObject { $0.count > 0 }.map { // Allow partial match of each term. - $0 + "*" + // + // Note that we use double-quotes to enclose each search term. + "\"\($0)\"*" } // 6. Join terms into query string. @@ -92,8 +94,17 @@ public class FullTextSearchFinder: NSObject { var charactersToFilter = CharacterSet.punctuationCharacters charactersToFilter.formUnion(CharacterSet.illegalCharacters) charactersToFilter.formUnion(CharacterSet.controlCharacters) - // Note that we strip the Unicode "subtitute" character (26). - charactersToFilter.formUnion(CharacterSet(charactersIn: "+~$^=|<>`_\u{26}")) + + // We want to strip all ASCII characters except: + // * Letters a-z, A-Z + // * Numerals 0-9 + // * Whitespace + var asciiToFilter = CharacterSet(charactersIn: UnicodeScalar(0x0)!.. YapDatabaseFullTextSearchTransaction? { return transaction.ext(FullTextSearchFinder.dbExtensionName) as? YapDatabaseFullTextSearchTransaction