Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting objects by type #1162

Merged
merged 6 commits into from
Nov 10, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Quicksilver/Code-QuickStepCore/QSLibrarian.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ extern QSLibrarian *QSLib; // Shared Instance
//- (BOOL)loadIndexesForEntries:(NSArray *)theEntries;
- (void)recalculateTypeArraysForItem:(QSCatalogEntry *)entry;
- (NSArray *)arrayForType:(NSString *)string;
- (NSArray *)scoredArrayForType:(NSString *)string;
- (NSDictionary *)typeArraysFromArray:(NSArray *)array;
- (void)loadMissingIndexes;
- (void)savePasteboardHistory;
Expand Down
7 changes: 6 additions & 1 deletion Quicksilver/Code-QuickStepCore/QSLibrarian.m
Original file line number Diff line number Diff line change
Expand Up @@ -478,12 +478,17 @@ - (NSArray *)arrayForType:(NSString *)string {
return [typeSet allObjects];
}

- (NSArray *)scoredArrayForType:(NSString *)string
{
// return all objects of this type, sorted by rank
return [self scoredArrayForString:nil inSet:[self arrayForType:string] mnemonicsOnly:YES];
}

- (NSDictionary *)typeArraysFromArray:(NSArray *)array {
NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithCapacity:1];
NSMutableArray *typeEntry;
for(QSObject *object in array) {
for (NSString *key in [object dataDictionary]) {
for (NSString *key in [[object dataDictionary] allKeys]) {
if ([key hasPrefix:@"QSObject"]) continue;
typeEntry = [dict objectForKey:key];
if (!typeEntry) {
Expand Down
16 changes: 10 additions & 6 deletions Quicksilver/Code-QuickStepCore/QSObjectRanker.m
Original file line number Diff line number Diff line change
Expand Up @@ -185,16 +185,20 @@ - (QSRankedObject *)rankedObject:(QSBasicObject *)object forAbbreviation:(NSStri
#endif
}

NSInteger useCount = 0;

// get number of times this abbrev. has been used
if ([anAbbreviation length])
NSUInteger useCount = 0;
if ([anAbbreviation length]) {
useCount = [[usageMnemonics objectForKey:anAbbreviation] integerValue];
} else {
// for an empty string, consider the total use count
for (id key in usageMnemonics) {
useCount += [[usageMnemonics objectForKey:key] integerValue];
}
}

if (useCount) {
newScore += (1-1/(useCount+1) );

} else if (newScore) {
newScore += 1.0 - 1.0 / (useCount + 1.0);
} else if (newScore && [anAbbreviation length]) {
// otherwise add points for similar starting abbreviations
for (id key in usageMnemonics) {
if (prefixCompare(key, anAbbreviation) == NSOrderedSame) {
Expand Down