Friday, November 22, 2024

spotlight – Can’t Search Within Folders on a Drive?

I have a weird Spotlight issue with one of my external drives; I can search the drive as a whole just fine, but if I try to search only a specific folder within it then the search simply doesn’t work.

To give an example, let’s say I had a file /Volumes/MyDrive/Pictures/Image.png, if I run:

mdfind -onlyin /Volumes/MyDrive '*.png'

The results will include the file exactly as I expect. However if I instead run the following:

mdfind -onlyin /Volumes/MyDrive/Pictures '*.png'

It instead returns nothing, even though the image is in that folder, and it’s definitely known to Spotlight (it is returned in the correct path when searching at a higher level).

This issue seems to apply to searching any folder within the drive, no matter how nested, it affects newly created folders and so-on so it shouldn’t be an issue with permissions or extended attributes (as a new folder should have default permissions and no extended attributes).

I’ve already tried re-creating the index via the following:

sudo mdutil -i off /Volumes/MyDrive
sudo mdutil -X /Volumes/MyDrive
sudo mdutil -i on /Volumes/MyDrive

After the second step I also verified that the .Spotlight-V100 folder had been fully removed from the drive, so when indexing is turned on the index should be created 100% fresh.

However the exact same issue continues after indexing is complete; for whatever reason I just cannot search inside any folders, all my searches have to be of the entire drive (or my entire Mac) or they won’t return anything within the drive at all.

Anyone have any other suggestions about what I can try to fix this? Why in the heck would Spotlight work fine with -onlyin for the drive, but not a folder within it? It’s such a bizarre issue!

Related Articles

Latest Articles