Michal Moravec
Michal Moravec

Reputation: 46

mdfind query weird behaviour

Look at this mdfind query:

mdfind 'kMDItemFSName = "Pages.app" || kMDItemFSName = "Keynote.app" || kMDItemFSName = "Numbers.app"'  

Is there something wrong with it? Perhaps logical OR - || which is not documented by Apple on mdfind man page?

In 99% cases, mdfind returns three file paths / locations of each iwork app (or nothing when they are not installed).

/Applications/iWork '09/Pages.app   
/Applications/iWork '09/Keynote.app  
/Applications/iWork '09/Numbers.app

But in ~1-5% (10.8.2) I get this from mdfind:

/Applications/iWork '09/Keynote.app  
/Applications/Mail.app  
/Applications/Messages.app  
/Applications/Utilities/Migration Assistant.app  
/Applications/Notes.app  
...  
/Library/Scripts/Printing Scripts/Convert To PDF.scpt  
/Library/Scripts/Printing Scripts/Convert To PostScript.scpt  
/Library/Scripts/Printing Scripts/Print Window With Subfolders.scpt  
/Library/Scripts/Printing Scripts/Print Window.scpt  
...  
/System/Library/Frameworks/GameKit.framework/Versions/A/Resources/GKNavbarBackButtonNormalLandscape.png  
/System/Library/Frameworks/GameKit.framework/Versions/A/Resources/[email protected]*  

------------ List goes on (tons of stuff) ------------  

Is there something wrong with my mdfind query, OR is there something wrong with Spotlight database?

Certainly a possibility: There is serious bug in Spotlight introduced with 10.7.5 and 10.8.2 updates (check https://discussions.apple.com/message/19863234#19863234 )

Thanks :-)

Upvotes: 2

Views: 1235

Answers (1)

Tom Andersen
Tom Andersen

Reputation: 7200

I don't know what is going on here. It seems that Spotlight is broken for OR searching on kMDItemFS* ?

I hand created an OR based Spotlight search in the Finder - it fails.

I downloaded HoudahSpot and made a simple 'Filename' is Pages.app OR Filename is Keynote.app query and got the same results - over 50,000

So it does not look like its merely a bug in mdfind's interpretation of the query.

As a further clue: Any item with FS in the name - example kMDItemFSName - is not stored in the Spotlight Database, so queries take much longer.

 mdfind "kMDItemCFBundleIdentifier == 'com.apple.iWork.Pages'  || kMDItemCFBundleIdentifier == 'com.apple.iWork.Keynote'"

works about 1000x faster on my computer.

In this guide which is 5 years or so old, they mention using a single | for OR, but that does not work for me on 10.8.2 http://macdevcenter.com/pub/a/mac/2006/01/04/mdfind.html

Upvotes: 1

Related Questions