2

Currently, spotlight will only search the title of docx files, not the contents. Is there any way to fix this?

2
  • This is happening for me, but only for files created or modified since mid-April.
    – Gilby
    Jun 4, 2017 at 4:31
  • Rebuilt index - now all docx do not have content indexed.
    – Gilby
    Jun 4, 2017 at 5:20

2 Answers 2

3

Yes there is a way. My answer is based on this discussion in Apple Communities. My summary:

There are two spotlight importers for Office documents.

  • /Library/Spotlight/Microsoft Office.mdimporter

  • /System/Library/Spotlight/RichText.mdimporter

Both are included in MacOS and the Microsoft Office importer has been updated in recent MacOS updates (I have checked 10.12.4 and 10.12.5).

By default, when Word changes a document the MS importer is used. And that is where the problem lies! The Apple importer works correctly.

You can see your documents appearing and disappearing in Spotlight searches by doing these two commands:

$ mdimport -d1 [path to docx]

That uses the system default importer /System/Library/Spotlight/RichText.mdimporter and the document appears in Spotlight.

$ mdimport -d1 -g /Library/Spotlight/Microsoft\ Office.mdimporter [path to docx]

And the document disappears from Spotlight.

Solutions to the problem:

  1. Write a script which you run every hour to reindex any new .docx
  2. Delete the Microsoft provide importer /Library/Spotlight/Microsoft Office.mdimporter

I have deleted the Microsoft importer. And I must remember to delete it after every Office update.

Warning: If you do delete the Microsoft importer, Spotlight no longer indexes the content of Excel files!

Please note I am not happy with this answer. I have copied the Microsoft Office importer from my MacBook (where indexing has been working correctly) to my desktop (where it has been failing) and now all new or modified documents are indexed correctly. Both are running 10.12.5. And both give architecture mismatch errors when documents are indexed by mdimport in Terminal.

1
  • I am having doubts about the above. Not whole story. I have no problem with docx content on my MacBook. Only have issue on my desktop.
    – Gilby
    Jun 4, 2017 at 9:38
0

From what I read in here, and on Apple communities, I understood that the problem is that /Library/Spotlight/Microsoft Office.mdimporter is used to index docx files, which it doesn’t properly handle. Removing the importer fixes the problem, but breaks old Word (.doc) and Excel file indexing. Explicitly calling mdimport also does, but has to be done each time file is modified. I am not sure how Spotlight decides, which importer to use to handle specific file types, but in the info.plist for the misbehaving Microsoft mdimporter I found a mention of docx. I made a backup copy of the Info.plist, removed the array element describing docx (…):

    <dict>
        <key>UTTypeConformsTo</key>
        <array>
            <string>public.data</string>
        </array>
        <key>UTTypeDescription</key>
        <string>Microsoft Word document</string>
        <key>UTTypeIdentifier</key>
        <string>com.microsoft.word.openxml.document</string>
        <key>UTTypeTagSpecification</key>
        <dict>
            <key>com.apple.ostype</key>
            <string>WXBN</string>
            <key>public.filename-extension</key>
            <array>
                <string>docx</string>
            </array>
            <key>public.mime-type</key>
            <string>application/vnd.openxmlformats-officedocument.wordprocessingml.document</string>
        </dict>
    </dict>

and saved. However, newly created or edited docx files were still not searchable by spotlight. I wasn’t sure the changes I made were noticed by spotlight, so I rebooted my Mac, still the same. Finally I changed the modification date on the mdimporter (touch /Library/Spotlight/Microsoft\ Office.mdimporter). After this the docx files I create and modify are promptly indexed automatically. I am not sure whether this solution will last and if it will survive software updates.

2
  • This doesn't work anymore for me, neither does deleting Microsoft Office.mdimporter. Re-indexing still works. I also tried to unlink RichText.mdimporter from the UTI associated with docx, based on the results of comprehensive testing done by jafingerhut, but it didn't help either. Sep 17, 2018 at 16:24
  • Whenever Microsott Office importer is used, whether by forcing it in "mdimport -g" or by modfying RichText mdimporter's info.plist, full text index of docx files is not created. The files are indexed (mdls output), but the full text content kMDItemTextContent isn't created mdimport -d2. Sep 17, 2018 at 16:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .