• 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
NSPredicate & Spotlight query strings
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSPredicate & Spotlight query strings


  • Subject: NSPredicate & Spotlight query strings
  • From: Chris Kane <email@hidden>
  • Date: Mon, 4 Jul 2005 19:26:04 -0700

On Jul 3, 2005, at 4:25 AM, Ken Tozier wrote:
again.. interesting.. I think this must be a problem with your app, because if you run the Spotlighter example, and enter *String File* you get loads of .strings files showing up


I'm thinking that the string parser in NSPredicate's predicateWithFormat method might not be 100% yet.


It's not that +predicateWithFormat: is not 100% yet, but rather that the syntaxes are different. People are looking at one subsystem, which implements a query string syntax, and another subsystem, which implements a query string syntax, and assuming that they are the same. They are similar, but differ in several respects. There's no particular relationship between Spotlight and NSPredicate, other than NSMetadataQuery is the Cocoa interface to Spotlight and uses NSPredicate in its API. I'd say the main client of NSPredicate is CoreData, though.

[The questions of "Should they have been the same?" or "Why aren't..." are subjective issues I'm not going to address. The fact is they aren't the same.]


In my understanding, ...

1) Spotlight's query syntax is generally more limited than NSPredicate's. For example, Spotlight requires "KEY operator VALUE" in comparison clauses, and doesn't accept "VALUE operator KEY". Also, the kinds of things Spotlight accepts for VALUE is more limited than NSPredicate.

2) As a partial consequence of (1), string literals don't always have to be quoted in Spotlight queries. When VALUE is a string and no special operators need to be applied to it, you can leave off the quotes. You cannot do this in NSPredicate query strings, as the result would be ambiguous. Spotlight will have a harder time making certain types of extensions to the query string syntax (if it wanted to do so) in the future because it does not require the quotes today.

3) The case-insensitive/dicritic-insensitive/etc syntax for Spotlight queries is different from the NSPredicate version. In Spotlight, you do this: "myAttr == 'foo'cd"; in NSPredicate strings, you do this: "myAttr ==[cd] 'foo'". In both cases, 'cd' means case-insensitive and diacritic-insensitive, and either modify the operator or make a different operator, depending on your point of view. Spotlight puts the modifiers on the value, NSPredicate puts the modifiers on the operator.

4) MDQuery operators cannot appear in the VALUE (of KEY op VALUE) in the NSPredicate string. For example, to write a "is-substring-of" expression, in Spotlight you do: "myAttr = '*foo*'", in NSPredicate strings you do: "myAttr contains 'foo'". Spotlight takes glob-like expressions, NSPredicate uses a different operator.

5) "*" as left-hand-side key in a comparison expression: in Spotlight this means "any key in the item", and can only be used with == [or =] (I believe). There is a syntax for NSPredicate strings for this, but it isn't public currently, so I'm not going to describe it. And of course it would apply only to NSMetadataQuery use of NSPredicates. One can fake it up today by creating the NSPredicate clause "by hand" as shown in the Spotlighter example; again, something only useful when you're using the NSPredicate with NSMetadataQuery.


So, the functionality is there in either case, it's just that the Spotlight syntax is different from the NSPredicate syntax. One string could be converted into the other string form, as long as the common subset of functionality is used. I don't know of any API or SPI to do so, however, in the system.



Chris Kane Cocoa Frameworks, Apple

_______________________________________________
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


  • Prev by Date: Re: Linking libxml and libxslt
  • Next by Date: Re: DO and NSProxy
  • Previous by thread: NSTableView CheckBoxes & selection
  • Next by thread: Re: DO and NSProxy
  • Index(es):
    • Date
    • Thread