match highlight behavior with search behavior

pull/2/head
Michael Kirk 5 years ago
parent 8caff1a535
commit 05d8846f6c

@ -82,11 +82,12 @@ extension ConversationSearchController: UISearchResultsUpdating {
public func updateSearchResults(for searchController: UISearchController) { public func updateSearchResults(for searchController: UISearchController) {
Logger.verbose("searchBar.text: \( searchController.searchBar.text ?? "<blank>")") Logger.verbose("searchBar.text: \( searchController.searchBar.text ?? "<blank>")")
guard let searchText = searchController.searchBar.text?.stripped else { guard let rawSearchText = searchController.searchBar.text?.stripped else {
self.resultsBar.updateResults(resultSet: nil) self.resultsBar.updateResults(resultSet: nil)
self.delegate?.conversationSearchController(self, didUpdateSearchResults: nil) self.delegate?.conversationSearchController(self, didUpdateSearchResults: nil)
return return
} }
let searchText = FullTextSearchFinder.normalize(text: rawSearchText)
BenchManager.startEvent(title: "Conversation Search", eventId: searchText) BenchManager.startEvent(title: "Conversation Search", eventId: searchText)
guard searchText.count >= ConversationSearchController.kMinimumSearchTextLength else { guard searchText.count >= ConversationSearchController.kMinimumSearchTextLength else {

@ -708,10 +708,12 @@ NS_ASSUME_NONNULL_BEGIN
initWithString:text initWithString:text
attributes:@{ NSFontAttributeName : font, NSForegroundColorAttributeName : textColor }]; attributes:@{ NSFontAttributeName : font, NSForegroundColorAttributeName : textColor }];
if (searchText.length >= ConversationSearchController.kMinimumSearchTextLength) { if (searchText.length >= ConversationSearchController.kMinimumSearchTextLength) {
NSString *searchableText = [FullTextSearchFinder normalizeWithText:searchText];
NSError *error; NSError *error;
NSRegularExpression *regex = [[NSRegularExpression alloc] initWithPattern:searchText NSRegularExpression *regex =
options:NSRegularExpressionCaseInsensitive [[NSRegularExpression alloc] initWithPattern:[NSRegularExpression escapedPatternForString:searchableText]
error:&error]; options:NSRegularExpressionCaseInsensitive
error:&error];
OWSAssertDebug(error == nil); OWSAssertDebug(error == nil);
for (NSTextCheckingResult *match in for (NSTextCheckingResult *match in
[regex matchesInString:text options:NSMatchingWithoutAnchoringBounds range:NSMakeRange(0, text.length)]) { [regex matchesInString:text options:NSMatchingWithoutAnchoringBounds range:NSMakeRange(0, text.length)]) {

@ -138,6 +138,7 @@ public class FullTextSearchFinder: NSObject {
// This is a hot method, especially while running large migrations. // This is a hot method, especially while running large migrations.
// Changes to it should go through a profiler to make sure large migrations // Changes to it should go through a profiler to make sure large migrations
// aren't adversely affected. // aren't adversely affected.
@objc
public class func normalize(text: String) -> String { public class func normalize(text: String) -> String {
// 1. Filter out invalid characters. // 1. Filter out invalid characters.
let filtered = text.removeCharacters(characterSet: charactersToRemove) let filtered = text.removeCharacters(characterSet: charactersToRemove)

Loading…
Cancel
Save