Created
March 19, 2014 16:48
-
-
Save chrisladd/9645970 to your computer and use it in GitHub Desktop.
Some very old code implementing basic search split on words. Don't judge.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-(void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText { | |
NSMutableSet *uniqueCharts = [NSMutableSet set]; | |
NSMutableCharacterSet *charSet = [[NSMutableCharacterSet alloc] init]; | |
[charSet formUnionWithCharacterSet:[NSCharacterSet punctuationCharacterSet]]; | |
[charSet formUnionWithCharacterSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; | |
NSArray *words = [searchText componentsSeparatedByCharactersInSet:charSet]; | |
BOOL firstLoop = YES; | |
for (NSString *aWord in words) { | |
if (aWord.length < 3) { | |
break; | |
} | |
NSPredicate *aPredicate = [NSPredicate prefixMatchingPredicateForString:aWord withKeyPath:@"word"]; | |
if (!aPredicate) { | |
break; | |
} | |
NSArray *results = [self fetchChartsWithPredicate:aPredicate]; // returns a unique array of TncManagedCharts | |
// on the first run, populate with the results. On subsequent runs, intersect the two | |
if (firstLoop) { | |
uniqueCharts = [NSMutableSet setWithArray:results]; | |
firstLoop = NO; | |
} else { | |
[uniqueCharts intersectSet:[NSSet setWithArray:results]]; | |
} | |
if (IsEmpty(uniqueCharts)) { | |
// if we have no results, we won't have any on subsequent loops either. So no need to search further | |
self.searchArray = nil; | |
return; | |
} | |
} | |
[self resetSearchArrayFromUniqueCharts:uniqueCharts]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think I actually meant
continue
above where I saidbreak