match highlight behavior with search behavior

This commit is contained in:
Michael Kirk 2019-03-29 10:56:04 -06:00
parent 8caff1a535
commit 05d8846f6c
3 changed files with 8 additions and 4 deletions

View File

@ -82,11 +82,12 @@ extension ConversationSearchController: UISearchResultsUpdating {
public func updateSearchResults(for searchController: UISearchController) {
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.delegate?.conversationSearchController(self, didUpdateSearchResults: nil)
return
}
let searchText = FullTextSearchFinder.normalize(text: rawSearchText)
BenchManager.startEvent(title: "Conversation Search", eventId: searchText)
guard searchText.count >= ConversationSearchController.kMinimumSearchTextLength else {

View File

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

View File

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