diff --git a/Vector/Model/RoomList/PublicRoomsDirectoryDataSource.h b/Vector/Model/RoomList/PublicRoomsDirectoryDataSource.h index 3c72abd8f..6af1fe85f 100644 --- a/Vector/Model/RoomList/PublicRoomsDirectoryDataSource.h +++ b/Vector/Model/RoomList/PublicRoomsDirectoryDataSource.h @@ -39,7 +39,7 @@ /** The filter being applied. Nil if there is no filter. - A 'OR' search is made on the strings of the array. + A 'AND' search is made with the strings of the array. Setting a new value may trigger a request to the home server. So, the data source state may change to MXKDataSourceStatePreparing. */ diff --git a/Vector/Model/RoomList/PublicRoomsDirectoryDataSource.m b/Vector/Model/RoomList/PublicRoomsDirectoryDataSource.m index 539dd8300..0c75334da 100644 --- a/Vector/Model/RoomList/PublicRoomsDirectoryDataSource.m +++ b/Vector/Model/RoomList/PublicRoomsDirectoryDataSource.m @@ -124,15 +124,21 @@ double const kPublicRoomsDirectoryDataExpiration = 10; { if ([filteredRooms indexOfObjectIdenticalTo:publicRoom] == NSNotFound) { - // Do a OR search + // Do a AND search + BOOL matchAll = YES; for (NSString *pattern in _searchPatternsList) { - if ([publicRoom.displayname rangeOfString:pattern options:NSCaseInsensitiveSearch].location != NSNotFound) + if (pattern.length && NO == [publicRoom.displayname localizedCaseInsensitiveContainsString:pattern]) { - [filteredRooms addObject:publicRoom]; + matchAll = NO; break; } } + + if (matchAll) + { + [filteredRooms addObject:publicRoom]; + } } } diff --git a/Vector/ViewController/HomeViewController.m b/Vector/ViewController/HomeViewController.m index 868c901b5..23a45f96e 100644 --- a/Vector/ViewController/HomeViewController.m +++ b/Vector/ViewController/HomeViewController.m @@ -490,10 +490,13 @@ { self.selectedViewController.view.hidden = NO; + // Do a AND search on words separated by a space + NSArray *patterns = [searchBar.text componentsSeparatedByString:@" "]; + // Forward the search request to the data source if (self.selectedViewController == recentsViewController) { - [recentsDataSource searchWithPatterns:@[searchBar.text]]; + [recentsDataSource searchWithPatterns:patterns]; recentsViewController.shouldScrollToTopOnRefresh = YES; } }