Public rooms search: Do a AND search on public rooms

This commit is contained in:
manuroe
2015-12-21 16:41:41 +01:00
parent 94fbcc076f
commit d65efac3d5
3 changed files with 14 additions and 5 deletions
@@ -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.
*/
@@ -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];
}
}
}
+4 -1
View File
@@ -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;
}
}