spotlight can not find certain files?

I am trying to locate a pdf file (the pdf can be downloaded from https://www.frontiersin.org/articles/10.3389/fphys.2019.00094/full) with the following command.


```

mdfind -onlyin . "(kMDItemTextContent=='oxidative stress'c) && (kMDItemFSName=='*.pdf')"

```


But I don't find it. The file is in the spotlight database. The output of the following command is attached. The field kMDItemTextContent does contain "oxidative stress". Does anybody know why spotlight can not find it? Thanks.



```

mdimport -d2 30814954.pdf

```

MacBook Air 13", macOS 10.14

Posted on Feb 19, 2020 9:14 PM

Reply
8 replies

Feb 20, 2020 6:12 AM in response to Eau Rouge

It sounds like the problem was that the file would take time to be indexed. How to force indexing a file immediately on command line? Thanks.


$ mv ../fphys-10-00094.pdf .

$ sha1sum *.pdf

4c3c0f5aaea037a59aa1377dbd88c8fcc69a054e 30814954.pdf

4c3c0f5aaea037a59aa1377dbd88c8fcc69a054e fphys-10-00094.pdf

$ mdfind -onlyin . "(kMDItemTextContent=='oxidative stress'c) && (kMDItemFSName=='*.pdf')"

/Users/xyz/Downloads/y/30814954.pdf


PS, I use command line because such search can be automated.


Feb 20, 2020 9:45 AM in response to pengyu.ut

After a while, I saw.


$ mdfind -onlyin . "(kMDItemTextContent=='oxidative stress'c) && (kMDItemFSName=='*.pdf')"

/private/tmp/30814954.pdf

/Users/xyz/Downloads/y/fphys-10-00094.pdf


When I moved 30814954.pdf to /tmp, it still showed the above for some time. Then the output was changed to this. Notice the file in /tmp is shown.


$ mdfind -onlyin . "(kMDItemTextContent=='oxidative stress'c) && (kMDItemFSName=='*.pdf')"

/private/tmp/30814954.pdf

/Users/xyz/Downloads/y/fphys-10-00094.pdf


This is weired. Is there a way to make spotlight database update instantaneously?

Feb 19, 2020 9:26 PM in response to pengyu.ut

Did you download the file from the link that you provided, in all probability it will get downloaded to your Downloads folder. To check where Downloads go look in your browser preferences. For example in Safari click on Safari in the menubar and click on Preferences> General> File download location. If you use another browser then you should have something similar.

Have a look in System Preferences> Spotlight> Search Results and make sure PDF Documents has been checked.

Feb 19, 2020 10:00 PM in response to Eau Rouge

This is not helpful. The file obvious should be in `.` already, as I am using the command line. Could you test the commands before replying?


I could find the file by the following command. But it takes a long time to finish after finding the pdf file (there is just one pdf file in the current directly). Is this normal?


It is strange that I have to use * before and after the query. I'd expect a syntax more like regex in grep be more intuitive. Where is the search syntax documented? Is regex possible with mdfind?


```

mdfind -onlyin . "(kMDItemTextContent=='*oxidative stress*'c) && ((kMDItemFSName=='*.pdf'))"

```

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

spotlight can not find certain files?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.