Spotlight can now search form multiple terms properly. Songs can be imported into the playlist again.

CQTexperiment
matthewleon 2008-02-12 16:24:09 +00:00
parent 7c2d290871
commit 4f9ac97dfc
7 changed files with 743 additions and 625 deletions

View File

@ -108,6 +108,7 @@
5604D45B0D60349B004F5C5D /* SpotlightWindowController.m in Sources */ = {isa = PBXBuildFile; fileRef = 5604D4590D60349B004F5C5D /* SpotlightWindowController.m */; };
5604D4F60D60726E004F5C5D /* SpotlightPlaylistEntry.m in Sources */ = {isa = PBXBuildFile; fileRef = 5604D4F50D60726E004F5C5D /* SpotlightPlaylistEntry.m */; };
562EA72E0D60CC5B0017B2B7 /* SpotlightTransformers.m in Sources */ = {isa = PBXBuildFile; fileRef = 562EA72D0D60CC5B0017B2B7 /* SpotlightTransformers.m */; };
56462DDA0D61D71E000AB68C /* SpotlightPlaylistView.m in Sources */ = {isa = PBXBuildFile; fileRef = 56462DD90D61D71E000AB68C /* SpotlightPlaylistView.m */; };
8D11072B0486CEB800E47090 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 089C165CFE840E0CC02AAC07 /* InfoPlist.strings */; };
8D11072D0486CEB800E47090 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 29B97316FDCFA39411CA2CEA /* main.m */; settings = {ATTRIBUTES = (); }; };
8D11072F0486CEB800E47090 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */; };
@ -598,6 +599,8 @@
5604D4F40D60726E004F5C5D /* SpotlightPlaylistEntry.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SpotlightPlaylistEntry.h; path = Spotlight/SpotlightPlaylistEntry.h; sourceTree = "<group>"; };
5604D4F50D60726E004F5C5D /* SpotlightPlaylistEntry.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SpotlightPlaylistEntry.m; path = Spotlight/SpotlightPlaylistEntry.m; sourceTree = "<group>"; };
562EA72D0D60CC5B0017B2B7 /* SpotlightTransformers.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SpotlightTransformers.m; sourceTree = "<group>"; };
56462DD80D61D71E000AB68C /* SpotlightPlaylistView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SpotlightPlaylistView.h; path = Spotlight/SpotlightPlaylistView.h; sourceTree = "<group>"; };
56462DD90D61D71E000AB68C /* SpotlightPlaylistView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SpotlightPlaylistView.m; path = Spotlight/SpotlightPlaylistView.m; sourceTree = "<group>"; };
566D32160D538550004466A5 /* APL.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = APL.xcodeproj; path = Plugins/APL/APL.xcodeproj; sourceTree = "<group>"; };
8D1107310486CEB800E47090 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist; path = Info.plist; sourceTree = "<group>"; };
8E07AAEE0AAC910500A4B32F /* SS_PreferencePaneProtocol.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = SS_PreferencePaneProtocol.h; path = Preferences/SS_PreferencePaneProtocol.h; sourceTree = "<group>"; };
@ -1094,6 +1097,8 @@
5604D4F40D60726E004F5C5D /* SpotlightPlaylistEntry.h */,
5604D4F50D60726E004F5C5D /* SpotlightPlaylistEntry.m */,
562EA72D0D60CC5B0017B2B7 /* SpotlightTransformers.m */,
56462DD80D61D71E000AB68C /* SpotlightPlaylistView.h */,
56462DD90D61D71E000AB68C /* SpotlightPlaylistView.m */,
);
name = Spotlight;
sourceTree = "<group>";
@ -1632,6 +1637,7 @@
5604D45B0D60349B004F5C5D /* SpotlightWindowController.m in Sources */,
5604D4F60D60726E004F5C5D /* SpotlightPlaylistEntry.m in Sources */,
562EA72E0D60CC5B0017B2B7 /* SpotlightTransformers.m in Sources */,
56462DDA0D61D71E000AB68C /* SpotlightPlaylistView.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};

File diff suppressed because it is too large Load Diff

View File

@ -44,7 +44,7 @@ static NSDictionary * tags;
@"length",
nil]retain];
extramdKeys = [[NSArray arrayWithObjects:
// @"kMDItemPath",
@"kMDItemPath",
@"kMDItemAuthors",
nil]retain];
allmdKeys = [[mdKeys arrayByAddingObjectsFromArray:extramdKeys]retain];
@ -68,9 +68,9 @@ static NSDictionary * tags;
forKey:[tags objectForKey:mdKey]];
}
// URL needs to be generated from the simple path stored in kMDItemPath
// Will deal with this complication later.
// [entry setURL: [NSURL fileURLWithPath: [songAttributes objectForKey:@"kMDItemPath"]]];
[entry setURL: [NSURL fileURLWithPath: [songAttributes objectForKey:@"kMDItemPath"]]];
// Authors is an array, but we only care about the first item in it

View File

@ -0,0 +1,17 @@
//
// SpotlightPlaylistView.h
// Cog
//
// Created by Matthew Grinshpun on 12/02/08.
// Copyright 2008 __MyCompanyName__. All rights reserved.
//
#import <Cocoa/Cocoa.h>
#import "PlaylistView.h"
@interface SpotlightPlaylistView : PlaylistView {
}
@end

View File

@ -0,0 +1,28 @@
//
// SpotlightPlaylistView.m
// Cog
//
// Created by Matthew Grinshpun on 12/02/08.
// Copyright 2008 __MyCompanyName__. All rights reserved.
//
#import "SpotlightPlaylistView.h"
@implementation SpotlightPlaylistView
- (void)awakeFromNib
{
[super awakeFromNib];
// We don't want the font to be bold
NSFontManager *fontManager = [NSFontManager sharedFontManager];
for(NSTableColumn *c in self.tableColumns)
{
[c.dataCell setFont:[fontManager convertFont:[c.dataCell font]
toHaveTrait:NSUnboldFontMask]];
}
}
@end

View File

@ -22,6 +22,7 @@
- (IBAction)changeSearchPath:(id)sender;
- (void)performSearch;
- (NSPredicate *)processSearchString;
@property(retain) NSMetadataQuery *query;
@property(copy) NSString *searchString;

View File

@ -45,23 +45,15 @@ static NSPredicate * musicOnlyPredicate = nil;
- (void)performSearch
{
unsigned options = (NSCaseInsensitivePredicateOption|
NSDiacriticInsensitivePredicateOption);
// Process the search string into a compound predicate
NSPredicate *searchPredicate = [self processSearchString];
// Set scope to contents of pathControl
[self.query setSearchScopes:[NSArray arrayWithObjects:pathControl.URL, nil]];
NSString *processedKey = [NSString stringWithFormat: @"*%@*", self.searchString];
NSPredicate *searchPredicate = [NSComparisonPredicate
predicateWithLeftExpression:[NSExpression expressionForKeyPath:@"kMDItemAuthors"]
rightExpression:[NSExpression expressionForConstantValue:processedKey]
modifier:NSDirectPredicateModifier
type:NSLikePredicateOperatorType
options:options];
// spotlightPredicate, which is what will finally be used for the spotlight search
// is the union of the bound NSSearchField and the static musicOnlyPredicate
// is the union of the (potentially) compound searchPredicate and the static
// musicOnlyPredicate
NSPredicate *spotlightPredicate = [NSCompoundPredicate andPredicateWithSubpredicates:
[NSArray arrayWithObjects: musicOnlyPredicate,
@ -74,6 +66,44 @@ static NSPredicate * musicOnlyPredicate = nil;
NSLog(@"Started query: %@", [self.query.predicate description], [[self.query class]description]);
}
- (NSPredicate *)processSearchString
{
// break the string up into an array of each word
NSArray * searchComponents = [self.searchString
componentsSeparatedByCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
// create an array of all the predicates to join together
NSMutableArray * subpredicates = [NSMutableArray
arrayWithCapacity:[searchComponents count]];
// we will ignore case and diacritics
unsigned options = (NSCaseInsensitivePredicateOption|
NSDiacriticInsensitivePredicateOption);
for(NSString *s in searchComponents)
{
// convert each "word" into "*word*"
NSString *processedKey = [NSString stringWithFormat: @"*%@*", s];
// Search all tags for something like word
NSPredicate *predicate = [NSComparisonPredicate
predicateWithLeftExpression:[NSExpression expressionForKeyPath:@"*"]
rightExpression:[NSExpression expressionForConstantValue:processedKey]
modifier:NSDirectPredicateModifier
type:NSLikePredicateOperatorType
options:options];
//TODO: Ability to search only artist, albums, etc.
[subpredicates addObject: predicate];
}
if ([subpredicates count] == 1)
return [subpredicates objectAtIndex: 0];
// Create a compound predicate from subPredicates
return [NSCompoundPredicate andPredicateWithSubpredicates: subpredicates];
}
- (void)dealloc
{
[self.query stopQuery];