Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Ranker options #1212

Merged
merged 3 commits into from

3 participants

@tiennou
Owner

Remove the boatload of arguments passed to QSDefaultRanker and pass them in an NSDictionary instead. I've tried to keep compatibility with other rankers (TextStart anyone ?) but didn't really test thoroughly (I'll try it and add commits if that's the case). Be aware that until the others rankers get updated, they will happily ignore unknown options.

Please consider that I did that because calling through [[NSUserDefault standardUserDefaults] boolForKey:@"QSUsePureStringRanking"] each time you'd be ranking something was apparent in an Instrument run I did to find out why the hell the result list took so long to keyboard through (both from the direct pane and the action pane).

My finding point out this thing as one culprit, the other being animating the interface when there's a indirect pane to show. But that's for another pull req ;-).

@skurfer
Owner

Haven't looked to see exactly what the problem is, but if you do some text ⇥ Find With…, the third pane is empty. It should contain all of your web searches, in order by rank.

@tiennou
Owner

Heh, silly me ;-).

@skurfer skurfer commented on the diff
Quicksilver/Code-QuickStepCore/QSLibrarian.m
@@ -652,7 +652,17 @@ - (NSMutableArray *)scoredArrayForString:(NSString *)searchString inSet:(id)set
- (NSMutableArray *)scoredArrayForString:(NSString *)searchString inSet:(NSArray *)set mnemonicsOnly:(BOOL)mnemonicsOnly {
if (!set) set = [defaultSearchSet allObjects];
- NSMutableArray *rankObjects = [QSDefaultObjectRanker rankedObjectsForAbbreviation:searchString inSet:set inContext:searchString mnemonicsOnly:mnemonicsOnly];
+ if (!searchString) searchString = @"";
+
+ BOOL usePureStringRanking = [[NSUserDefaults standardUserDefaults] boolForKey:@"QSUsePureStringRanking"];
@skurfer Owner
skurfer added a note

There's a macro defined for this called QSUsePureStringRanking in QSObjectRanker.m. Should we move that to QSLibrarian.h and use it instead of assigning it to a variable?

@skurfer Owner
skurfer added a note

Oh, never mind. I should have kept reading. :-)

@tiennou Owner
tiennou added a note

Heh ;-). The actual reason was that asking for that default before ranking each object was slightly inefficient. And then I went overboard and did that options thing ;-).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@pjrobertson

With this change, should you now change requiresRelaunch to NO in QSRegistration (search for "String Ranker")

@pjrobertson
Owner

Is your thinking that once this is merged, we can do something like you mentioned here. So I can close that pull request right?

Do you want to add it to this pull, before we forget?

@pjrobertson
Owner

I've made the changes, feel free to just cherry pick my commit 321a808

I now see @tiennou's point that if you omit items, you omit them for a reason - i.e. you do not want to see them at all. But I still think that the 'omit' option is to 'omit the items from showing in the catalog (when you search)', not 'omit the items from everywhere in Quicksilver'.
I think we have the right behaviour here

@skurfer
Owner

Is your thinking that once this is merged, we can do something like you mentioned here. So I can close that pull request right?

I thought we were going to close this and do something similar on #1198, but either way is fine with me.

@pjrobertson
Owner
@pjrobertson pjrobertson merged commit a5d2cdf into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
12 Quicksilver/Code-QuickStepCore/QSLibrarian.m
@@ -652,7 +652,17 @@ - (NSMutableArray *)scoredArrayForString:(NSString *)searchString inSet:(id)set
- (NSMutableArray *)scoredArrayForString:(NSString *)searchString inSet:(NSArray *)set mnemonicsOnly:(BOOL)mnemonicsOnly {
if (!set) set = [defaultSearchSet allObjects];
- NSMutableArray *rankObjects = [QSDefaultObjectRanker rankedObjectsForAbbreviation:searchString inSet:set inContext:searchString mnemonicsOnly:mnemonicsOnly];
+ if (!searchString) searchString = @"";
+
+ BOOL usePureStringRanking = [[NSUserDefaults standardUserDefaults] boolForKey:@"QSUsePureStringRanking"];
@skurfer Owner
skurfer added a note

There's a macro defined for this called QSUsePureStringRanking in QSObjectRanker.m. Should we move that to QSLibrarian.h and use it instead of assigning it to a variable?

@skurfer Owner
skurfer added a note

Oh, never mind. I should have kept reading. :-)

@tiennou Owner
tiennou added a note

Heh ;-). The actual reason was that asking for that default before ranking each object was slightly inefficient. And then I went overboard and did that options thing ;-).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
+ searchString, QSRankingContext,
+ set, QSRankingObjectsInSet,
+ [NSNumber numberWithBool:mnemonicsOnly], QSRankingMnemonicsOnly,
+ [NSNumber numberWithBool:usePureStringRanking], QSRankingUsePureString,
+ nil];
+
+ NSMutableArray *rankObjects = [QSDefaultObjectRanker rankedObjectsForAbbreviation:searchString options:options];
#ifdef DEBUG
NSDate *date = [NSDate date];
View
13 Quicksilver/Code-QuickStepCore/QSObjectRanker.h
@@ -11,12 +11,21 @@
@class QSBasicObject, QSRankedObject;
+/* Ranking options */
+extern NSString *QSRankingMnemonicsOnly; // BOOL
+extern NSString *QSRankingObjectsInSet; // NSArray
+extern NSString *QSRankingContext; // NSString, unused ?
+extern NSString *QSRankingUsePureString; // BOOL
+
@protocol QSObjectRanker
- (id)initWithObject:(QSBasicObject *)object;
//- (float)scoreForAbbreviation:(NSString*)anAbbreviation inContext:(NSString *)context;
//- (NSIndexSet*)maskForAbbreviation:(NSString*)anAbbreviation inContext:(NSString *)context;
+- (QSRankedObject *)rankedObject:(QSBasicObject *)object forAbbreviation:(NSString*)anAbbreviation options:(NSDictionary *)options;
- (NSString*)matchedStringForAbbreviation:(NSString*)anAbbreviation hitmask:(NSIndexSet **)hitmask inContext:(NSString *)context;
-- (QSRankedObject *)rankedObject:(QSBasicObject *)object forAbbreviation:(NSString*)anAbbreviation inContext:(NSString *)context withMnemonics:(NSArray *)mnemonics mnemonicsOnly:(BOOL)mnemonicsOnly;
+
+@optional
+- (QSRankedObject *)rankedObject:(QSBasicObject *)object forAbbreviation:(NSString*)anAbbreviation inContext:(NSString *)context withMnemonics:(NSArray *)mnemonics mnemonicsOnly:(BOOL)mnemonicsOnly DEPRECATED_ATTRIBUTE;
@end
@@ -25,5 +34,5 @@
NSObject <QSStringRanker> *nameRanker;
NSObject <QSStringRanker> *labelRanker;
}
-+ (NSMutableArray *)rankedObjectsForAbbreviation:(NSString*)anAbbreviation inSet:(NSArray *)set inContext:(NSString *)context mnemonicsOnly:(BOOL)mnemonicsOnly;
++ (NSMutableArray *)rankedObjectsForAbbreviation:(NSString *)anAbbreviation options:(NSDictionary *)options;
@end
View
117 Quicksilver/Code-QuickStepCore/QSObjectRanker.m
@@ -16,11 +16,9 @@
#import "QSRegistry.h"
#import "QSLibrarian.h"
-#define QSUsePureStringRanking [[NSUserDefaults standardUserDefaults] boolForKey:@"QSUsePureStringRanking"]
-
Class QSCurrentStringRanker = nil;
-typedef QSRankedObject * (*QSScoreForObjectIMP) (id instance, SEL selector, QSBasicObject *object, NSString* anAbbreviation, NSString *context, NSArray * mnemonics, BOOL mnemonicsOnly);
+typedef QSRankedObject * (*QSScoreForObjectIMP) (id instance, SEL selector, QSBasicObject *object, NSString *anAbbreviation, NSDictionary *options);
typedef CGFloat (*QSScoreForAbbrevIMP) (id object, SEL selector, NSString * abbreviation);
QSScoreForAbbrevIMP scoreForAbbrevIMP;
@@ -28,61 +26,88 @@
@implementation QSDefaultObjectRanker
+ (void)initialize {
NSString *className = [[NSUserDefaults standardUserDefaults] stringForKey:@"QSStringRankers"];
- if (!className) {
- className = @"QSDefaultStringRanker";
- }
-
- if (className) {
- QSCurrentStringRanker = NSClassFromString(className);
-
- if (!QSCurrentStringRanker) {
-
- // ok, maybe the bundle wasn't loaded right away, let's try to load it now
- NSBundle *rankerBundle = [QSReg bundleForClassName:className];
- if (rankerBundle && [rankerBundle load]) {
- QSCurrentStringRanker = NSClassFromString(className);
- }
+ [self setDefaultStringRanker:className];
+}
+
++ (BOOL)setDefaultStringRanker:(NSString *)className {
+ Class rankerClass = NSClassFromString(className);
+
+ if (!rankerClass) {
+ // ok, maybe the bundle wasn't loaded right away, let's try to load it now
+ NSBundle *rankerBundle = [QSReg bundleForClassName:className];
+ if (rankerBundle && [rankerBundle load]) {
+ rankerClass = NSClassFromString(className);
}
}
- if (!QSCurrentStringRanker) {
+
+ if (!rankerClass) {
QSShowNotifierWithAttributes([NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Ranker Changed", nil), QSNotifierTitle, NSLocalizedString(@"Could not load preferred string ranker. Switching to default", nil), QSNotifierText, [QSResourceManager imageNamed:kQSBundleID], QSNotifierIcon, nil]);
className = @"QSDefaultStringRanker";
- QSCurrentStringRanker = NSClassFromString(className);
+ rankerClass = NSClassFromString(className);
+ if (!rankerClass) {
+ [NSException raise:NSInternalInconsistencyException format:@"No %@ class found !", className];
+ }
}
-
- if (QSCurrentStringRanker)
+
+ if ([rankerClass instancesRespondToSelector:@selector(scoreForAbbreviation:)]) {
+ QSCurrentStringRanker = rankerClass;
scoreForAbbrevIMP = (QSScoreForAbbrevIMP) [QSCurrentStringRanker instanceMethodForSelector:@selector(scoreForAbbreviation:)];
- else
- [NSException raise:NSInternalInconsistencyException format:@"No %@ class found !", className];
+ return YES;
+ }
+ return NO;
}
+ (id)rankerForObject:(QSBasicObject *)object {
return [[[self alloc] initWithObject:object] autorelease];
}
-+ (NSMutableArray *)rankedObjectsForAbbreviation:(NSString*)anAbbreviation inSet:(NSArray *)set inContext:(NSString *)context mnemonicsOnly:(BOOL)mnemonicsOnly {
- NSArray *abbreviationMnemonics = [[QSMnemonics sharedInstance] abbrevMnemonicsForString:anAbbreviation];
-
- NSMutableArray *rankObjects = [NSMutableArray arrayWithCapacity:[set count]];
-
+NSString *QSRankingMnemonicsOnly = @"QSRankingMnemonicsOnly"; // BOOL
+NSString *QSRankingObjectsInSet = @"QSRankingObjectsInSet"; // NSArray
+NSString *QSRankingContext = @"QSRankingContext"; // NSString, unused ?
+NSString *QSRankingUsePureString = @"QSRankingUsePureString"; // BOOL
+NSString *QSRankingIncludeOmitted = @"QSRankingIncludeOmitted"; // BOOL
+
+NSString *QSRankingAbbreviationMnemonics = @"QSRankingAbbreviationMnemonics"; // NSArray (internal)
+
+
++ (NSMutableArray *)rankedObjectsForAbbreviation:(NSString *)anAbbreviation options:(NSDictionary *)anOptions {
+ NSArray *abbreviationMnemonics = [[QSMnemonics sharedInstance] abbrevMnemonicsForString:anAbbreviation];
+
+ NSMutableDictionary *options = [anOptions mutableCopy];
+ if (abbreviationMnemonics)
+ [options setObject:abbreviationMnemonics forKey:QSRankingAbbreviationMnemonics];
+
+ NSArray *objectsInSet = [options objectForKey:QSRankingObjectsInSet];
+ NSMutableArray *rankObjects = [NSMutableArray arrayWithCapacity:[objectsInSet count]];
+
+ BOOL includeOmitted = [[options objectForKey:QSRankingIncludeOmitted] boolValue];
QSBasicObject *thisObject;
QSScoreForObjectIMP scoreForObjectIMP =
- (QSScoreForObjectIMP) [self instanceMethodForSelector:@selector(rankedObject:forAbbreviation:inContext:withMnemonics:mnemonicsOnly:)];
+ (QSScoreForObjectIMP) [self instanceMethodForSelector:@selector(rankedObject:forAbbreviation:options:)];
- for (thisObject in set) {
- if ([[QSLibrarian sharedInstance] itemIsOmitted:thisObject]) continue;
+ for (thisObject in objectsInSet) {
+ if (!includeOmitted && [[QSLibrarian sharedInstance] itemIsOmitted:thisObject]) continue;
id ranker = [thisObject ranker];
QSRankedObject *rankedObject;
- if([ranker isKindOfClass:[QSDefaultObjectRanker class]])
- rankedObject = (*scoreForObjectIMP) (ranker, @selector(rankedObject:forAbbreviation:inContext:withMnemonics:),
- thisObject, anAbbreviation, context, abbreviationMnemonics, mnemonicsOnly);
- else
- rankedObject = [ranker rankedObject:thisObject forAbbreviation:anAbbreviation
+ if ([ranker isKindOfClass:[QSDefaultObjectRanker class]]) {
+ rankedObject = (*scoreForObjectIMP) (ranker, @selector(rankedObject:forAbbreviation:options:),
+ thisObject, anAbbreviation, options);
+ } else if ([ranker respondsToSelector:@selector(rankedObject:forAbbreviation:options:)]) {
+ rankedObject = [ranker rankedObject:thisObject
+ forAbbreviation:anAbbreviation
+ options:options];
+ } else {
+ /* Old non-option compat call */
+ BOOL mnemonicsOnly = [[options objectForKey:QSRankingObjectsInSet] boolValue];
+ NSString *context = [options objectForKey:QSRankingContext];
+ rankedObject = [ranker rankedObject:thisObject
+ forAbbreviation:anAbbreviation
inContext:context
withMnemonics:abbreviationMnemonics
mnemonicsOnly:mnemonicsOnly];
+ }
if (rankedObject) {
[rankObjects addObject:rankedObject];
@@ -91,6 +116,17 @@ + (NSMutableArray *)rankedObjectsForAbbreviation:(NSString*)anAbbreviation inSet
return rankObjects;
}
++ (NSMutableArray *)rankedObjectsForAbbreviation:(NSString *)anAbbreviation inSet:(NSArray *)set inContext:(NSString *)context mnemonicsOnly:(BOOL)mnemonicsOnly {
+ NSMutableDictionary *options = [NSMutableDictionary dictionary];
+ if (set)
+ [options setObject:set forKey:QSRankingObjectsInSet];
+ if (context)
+ [options setObject:context forKey:QSRankingContext];
+ if (mnemonicsOnly)
+ [options setObject:[NSNumber numberWithBool:mnemonicsOnly] forKey:QSRankingMnemonicsOnly];
+ return [self rankedObjectsForAbbreviation:anAbbreviation options:options];
+}
+
- (id)initWithObject:(QSBasicObject *)object {
if (self = [super init]) {
nameRanker = nil;
@@ -131,7 +167,12 @@ - (NSString*)matchedStringForAbbreviation:(NSString*)anAbbreviation hitmask:(NSI
return nil;
}
-- (QSRankedObject *)rankedObject:(QSBasicObject *)object forAbbreviation:(NSString*)anAbbreviation inContext:(NSString *)context withMnemonics:(NSArray *)mnemonics mnemonicsOnly:(BOOL)mnemonicsOnly {
+//- (QSRankedObject *)rankedObject:(QSBasicObject *)object forAbbreviation:(NSString*)anAbbreviation inContext:(NSString *)context withMnemonics:(NSArray *)mnemonics mnemonicsOnly:(BOOL)mnemonicsOnly {
+- (QSRankedObject *)rankedObject:(QSBasicObject *)object forAbbreviation:(NSString *)anAbbreviation options:(NSDictionary *)options {
+// NSString *context = [options objectForKey:QSRankingContext];
+ NSArray *mnemonics = [options objectForKey:QSRankingAbbreviationMnemonics];
+ BOOL mnemonicsOnly = [[options objectForKey:QSRankingMnemonicsOnly] boolValue];
+ BOOL usePureString = [[options objectForKey:QSRankingUsePureString] boolValue];
QSRankedObject *rankedObject = nil;
if ([object isKindOfClass:[QSRankedObject class]]) { // Reuse old ranked object if possible
rankedObject = (QSRankedObject *)object;
@@ -171,7 +212,7 @@ - (QSRankedObject *)rankedObject:(QSBasicObject *)object forAbbreviation:(NSStri
// NSLog(@"newscore %f %@", newScore, rankedObject);
- if (!QSUsePureStringRanking || mnemonicsOnly) {
+ if (!usePureString || mnemonicsOnly) {
//NSLog(@"mnem");
if (newScore) { // Add modifiers
if (mnemonics)
Something went wrong with that request. Please try again.