• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Spotlight search speed problems?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Spotlight search speed problems?


  • Subject: Re: Spotlight search speed problems?
  • From: Corbin Dunn <email@hidden>
  • Date: Thu, 16 Jun 2005 08:49:58 -0700

I am also wondering if I can run more than one set of search conditions in a query. For example, I want to search for files ending in both .radiusconfig and .stellarradius. Thanks!


Are you using Cocoa? Why not try the NSMetadataQuery class? There is an example: Spotlighter, in Developer/Examples/AppKit. In addition, the "iSpend" WWDC application has an example of how to do a particular search and create a Spotlight Plug-in (metadata importer). Find iSpend by searching for it on developer.apple.com

If you are using NSMetdataQuery, it is quite easy to do. Look at the documentation for NSPredicate.

http://developer.apple.com/samplecode/iSpend/listing47.html

Has some source, and in particular, this bit of code:

NSPredicate *predicateToRun = nil;
// In the example below, we create a predicate with a given format string that simply replaces %@ with the string that is to be searched for. By using "like", the query will end up doing a regular expression search similar to *foo* when you are searching for the word "foo". By using the [c], the NSCaseInsensitivePredicateOption will be set in the created predicate. The particular item type to search for, kMDItemTextContent, is described in MDItem.h.
NSString *predicateFormat = @"kMDItemTextContent like[c] %@";
predicateToRun = [NSPredicate predicateWithFormat:predicateFormat, _searchKey];


// Create a compound predicate that searches for any keypath which has a value like the search key. This broadens the search results to include things such as the author, title, and other attributes not including the content. This is done in code for two reasons: 1. The predicate parser does not yet support "* = Foo" type of parsing, and 2. It is an example of creating a predicate in code, which is much "safer" than using a search string.
unsigned options = (NSCaseInsensitivePredicateOption| NSDiacriticInsensitivePredicateOption);
NSPredicate *compPred = [NSComparisonPredicate
predicateWithLeftExpression:[NSExpression expressionForKeyPath:@"*"]
rightExpression:[NSExpression expressionForConstantValue:_searchKey]
modifier:NSDirectPredicateModifier
type:NSLikePredicateOperatorType
options:options];


// Combine the two predicates with an OR
predicateToRun = [NSCompoundPredicate orPredicateWithSubpredicates:[NSArray arrayWithObjects:compPred, predicateToRun, nil]];



---corbin _______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
References: 
 >Spotlight search speed problems? (From: Colin Cornaby <email@hidden>)

  • Prev by Date: Re: Using Bindings with Distrubuted Objects
  • Next by Date: Re: Modal dialog alternatives?
  • Previous by thread: Re: Spotlight search speed problems?
  • Next by thread: ABPeoplePickerView
  • Index(es):
    • Date
    • Thread