- (Source *) source;
- (uint32_t) rank;
-- (BOOL) matches:(NSString *)text;
+- (BOOL) matches:(NSArray *)query;
- (bool) hasSupportingRole;
- (BOOL) hasTag:(NSString *)tag;
- (void) install;
- (void) remove;
-- (bool) isUnfilteredAndSearchedForBy:(NSString *)search;
+- (bool) isUnfilteredAndSearchedForBy:(NSArray *)query;
- (bool) isUnfilteredAndSelectedForBy:(NSString *)search;
- (bool) isInstalledAndUnfiltered:(NSNumber *)number;
- (bool) isVisibleInSection:(NSString *)section;
return rank_;
}
-- (BOOL) matches:(NSString *)text {
- if (text == nil)
+- (BOOL) matches:(NSArray *)query {
+ if (query == nil || [query count] == 0)
return NO;
rank_ = 0;
NSRange range;
NSUInteger length;
+ [self parse];
+
string = [self id];
- range = [string rangeOfString:text options:MatchCompareOptions_];
- if (range.location != NSNotFound)
- rank_ -= 10 * (100000 / [string length]);
+ length = [string length];
+
+ for (NSString *term in query) {
+ range = [string rangeOfString:term options:MatchCompareOptions_];
+ if (range.location != NSNotFound)
+ rank_ -= 10 * 100000 / length;
+ }
string = [self name];
- range = [string rangeOfString:text options:MatchCompareOptions_];
- if (range.location != NSNotFound)
- rank_ -= 6 * (100000 / [string length]);
- [self parse];
+ for (NSString *term in query) {
+ range = [string rangeOfString:term options:MatchCompareOptions_];
+ if (range.location != NSNotFound)
+ rank_ -= 6 * 100000 / length;
+ }
string = [self shortDescription];
length = [string length];
+ NSUInteger stop(std::min<NSUInteger>(length, 100));
- range = [string rangeOfString:text options:MatchCompareOptions_ range:NSMakeRange(0, std::min<NSUInteger>(length, 100))];
- if (range.location != NSNotFound)
- rank_ -= 2 * (100000 / length);
+ for (NSString *term in query) {
+ range = [string rangeOfString:term options:MatchCompareOptions_ range:NSMakeRange(0, stop)];
+ if (range.location != NSNotFound)
+ rank_ -= 2 * 100000 / length;
+ }
return rank_ != 0;
}
cache->MarkDelete(iterator_, true);
} }
-- (bool) isUnfilteredAndSearchedForBy:(NSString *)search {
+- (bool) isUnfilteredAndSearchedForBy:(NSArray *)query {
_profile(Package$isUnfilteredAndSearchedForBy)
bool value(true);
_end
_profile(Package$isUnfilteredAndSearchedForBy$Match)
- value &= [self matches:search];
+ value &= [self matches:query];
_end
return value;
} }
- (void) setObject:(id)object forFilter:(SEL)filter {
+@synchronized (self) {
[self setFilter:filter];
[self setObject:object];
-}
+} }
- (NSMutableArray *) _reloadPackages {
@synchronized (database_) {
}
- (void) useSearch {
- [self setObject:[search_ text] forFilter:@selector(isUnfilteredAndSearchedForBy:)];
+ [self setObject:[[search_ text] componentsSeparatedByString:@" "] forFilter:@selector(isUnfilteredAndSearchedForBy:)];
[self clearData];
[self reloadData];
}
}
- (id) initWithDatabase:(Database *)database query:(NSString *)query {
- if ((self = [super initWithDatabase:database title:UCLocalize("SEARCH") filter:@selector(isUnfilteredAndSearchedForBy:) with:query])) {
+ if ((self = [super initWithDatabase:database title:UCLocalize("SEARCH") filter:@selector(isUnfilteredAndSearchedForBy:) with:[query componentsSeparatedByString:@" "]])) {
search_ = [[[UISearchBar alloc] init] autorelease];
[search_ setDelegate:self];
}
- (void) reloadData {
- [self setObject:[search_ text]];
+ id object([search_ text]);
+ if ([self filter] == @selector(isUnfilteredAndSearchedForBy:))
+ object = [object componentsSeparatedByString:@" "];
+
+ [self setObject:object];
[self resetCursor];
[super reloadData];