Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

10.4: Make Spotlight index PHP files System 10.4
Tiger only hintHere's how to get Spotlight to index your PHP scripts. In the Finder, navigate to /Library/Spotlight and locate SourceCode.mdiporter (this is installed with the Developer Tools). Select the file, control-click on it, and choose "Show Package Contents" from the pop-up menu. Now go into the Contents folder in the newly opened window. Double-click on info.plist (this should launch Property List Editor).

Click the triangle to expand Root, then expand CFBundleDocumentTypes, expand 0, then finally expand LSItemContentTypes. Click on the last number in the list (for me it was 6), then click the New Sibling button in the toolbar to add a new key. For the string value, enter public.php-script.

Close the Property List Editor and save when prompted. Go to a Terminal prompt and type:
mdimport -r /Library/Spotlight/SourceCode.mdimporter
Spotlight will now set to work indexing all your PHP files.

[robg adds: I tested this one, and it worked just as described.]
    •    
  • Currently 3.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (2 votes cast)
 
[45,928 views]  

10.4: Make Spotlight index PHP files | 22 comments | Create New Account
Click here to return to the '10.4: Make Spotlight index PHP files' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
10.4: Make Spotlight index PHP files
Authored by: jpbjpbjpbjpb on May 25, '05 10:29:12AM

Where'd you find the magic word for php scripts? I'd like to get Spotlight to index python and ruby scripts, but haven't found a list of new keys like this.



[ Reply to This | # ]
10.4: Make Spotlight index PHP files
Authored by: paladin on May 25, '05 11:08:39AM

http://www.huw.id.au/code/fileTypeIDs.html

Hope this helps :)



[ Reply to This | # ]
For any source file
Authored by: rev_karol on May 25, '05 11:12:46AM

So you can use mdls to find out the spotlight "type" of a file. Here's what I did for a python file:

$ <b>mdls foo.py</b>
foo.py -------------
kMDItemAttributeChangeDate = 2005-05-18 15:50:45 +0100
kMDItemContentCreationDate = 2005-05-18 15:50:44 +0100
kMDItemContentModificationDate = 2005-05-18 15:50:44 +0100
kMDItemContentType = "public.python-script"
kMDItemContentTypeTree = (
<b>"public.python-script"</b>,
"public.shell-script",
"public.script",
"public.source-code",
"public.plain-text",
"public.text",
"public.data",
"public.item",
"public.content"
)
...


so the ContentTypeTree thingy tells you that public.python-script will work.
I'd beware of the public.shell-script one. I'm guessing that OS X has a ton of system shell scripts and indexing them all could slow down spotlight a lot. Although I could be wrong.


Karol.



[ Reply to This | # ]
For any source file
Authored by: schwa on May 25, '05 04:46:46PM
THe trouble with hacking a the Source Code importer to get it to index python scripts is Apple never necessarily coded the importer to handle python scripts.

It might work. It might not.

It might work with PHP because PHP is closer to C/C++/ObjC than Python is. It might just work. It might crash mdimporter every time it is run.

Notice the mights. Apple very likely did not add python to the list of support UTTypes of their source code importer because they didn't design it to work with Python. Or perhaps they did. But unless you work for Apple YOU don't know. HAcking system components like this is dumb.

And with that mini-rant out of the way ;-) I've written a Python Metadata Importer myself. This importer does more than a plain text import - it actually parses the python files and scans for function names, class names and a bunch of other metadata...

HEre's the link:

http://toxicsoftware.com/blog/index.php/weblog/python_metadata_importer_released_for_tiger/



[ Reply to This | # ]

10.4: Make Spotlight index PHP files
Authored by: Azark on May 25, '05 11:02:38AM

I agree with the previous poster.
It would be nice to know how to do this for other language, not just PHP...

---
iMac G5 20" 1.8Ghz 1GB 10.4.1 /
PowerBook G4 12" 1.5Ghz 768MB 10.4.1 /
G4 400 AGP 768MB 10.4.1 /
G4 400 AGP 768MB OSX Server 10.3.9



[ Reply to This | # ]
10.4: Make Spotlight index PHP files
Authored by: paladin on May 25, '05 11:14:35AM

This is probably what you are looking for:

http://developer.apple.com/documentation/Carbon/Conceptual/understanding_utis/understand_utis_intro/chapter_1_section_1.html

also have a look at:
http://www.huw.id.au/code/fileTypeIDs.html



[ Reply to This | # ]
10.4: Make Spotlight index PHP files
Authored by: ppmax on May 25, '05 11:57:41AM

I use virtual hosts and change my httpd.conf file often--and would like it indexed.

mdls /etc/httpd/httpd.conf returns:
kMDItemContentType="dyn.ah62d4rv4ge80g55sq2"

How can I get the source code importer to deal with files of this nature? More general: how do you get Spotlight to index "generic" system files without resorting to using /Developer/Tools/SetFile to change the file type?



[ Reply to This | # ]
10.4: Make Spotlight index PHP files
Authored by: segdeha on May 25, '05 01:30:33PM
I tried this hint, logging in as admin first, and got the following error when I tried to reindex (trimmed to contain just one of each UTI type):

Asking server to reimport files with UTIs: (
    "dyn.ah62d4rv4gq81k3p2su11uppurb2c465dsmy1a7a", 
    "public.objective-c-source", 
    "public.c-header", 
    "public.c-plus-plus-header", 
    "com.sun.java-source", 
    "public.objective-c-plus-plus-source", 
    "public.php-script", 
    "public.c-plus-plus-source", 
    "public.c-source", 
)
What does this mean and how can I work around it?

[ Reply to This | # ]
10.4: Make Spotlight index PHP files
Authored by: schwa on May 25, '05 05:31:20PM

This is normal.

It means mdimport has asked the spotlight daemon to index all files that match that criteria.



[ Reply to This | # ]
10.4: Make Spotlight index PHP files
Authored by: schwa on May 25, '05 04:55:40PM
You shouldn't expect this (or any other importer) to work with any arbitrary file types just by modifying the mdimporter's Info.plist

Mdimporters are crafted for particular types of data and the authors of the importers know best how to set up their Info.plist

Hacking on the Info.plist is taking a gamble. Maybe it'll work. Maybe it'll work most of the time. But you're asking for trouble in the long run. When mdimpor crashs it does so silently in the background. The end user won't know unless she is paying close attention that anything is wrong.

If you want an mdimporter for some particular file format then ask the developer of the file format/write it yourself/find someone to write it for you. Don't just randomly modify config files and hope.



[ Reply to This | # ]

Use the RichText.mdimporter instead
Authored by: jaydisc on May 25, '05 09:27:30PM

I understand your concerns... and therefore suggest modifying /System/Library/Spotlight/RichText.mdimporter/ as all that plugin is looking for is simple text.



[ Reply to This | # ]
Use the RichText.mdimporter instead
Authored by: schwa on May 25, '05 09:47:39PM

Well I've had a quick sniff around Apple's Source Code mdimporter and all it seems to do is copy the contents of the file into the "kMDItemTextContent" attribute. This means it _should_ work for any kind of file. But of course I could be mistaken.

However the principal of my concern remains. You should not be modifying Info.plist settings for software you do not understand fully. And unless you're in possession of the source code you do NOT understand it enough to make these modifications without asking for trouble.



[ Reply to This | # ]
Use the RichText.mdimporter instead
Authored by: ppmax on May 26, '05 11:50:38AM

I think "asking for trouble" is a bit of an overstatement. As you can see from the UTI tree the SourceCode importer deals with text, and Python and PHP (and HTML for that matter--which does get indexed) is text. I believe the only concern is that Apple could update the importer and overwrite any changes made to the plist file.

Question: Since you wrote an importer for python you may have an answer for the question I posted above: how to deal with files have kMDItemContentType as "dyn.*"



[ Reply to This | # ]
Use the RichText.mdimporter instead
Authored by: schwa on May 26, '05 05:14:05PM

I think "asking for trouble" is a bit of an overstatement. As you can see from the UTI tree the SourceCode importer deals with text, and Python and PHP (and HTML for that matter--which does get indexed) is text. I believe the only concern is that Apple could update the importer and overwrite any changes made to the plist file.

Yeah but HTML and PHP and Python are dissimilar enough that one parser probably won't be able to parse all three. Heck why not get the SourceCode file to parse MS Word files - it's all just bytes at the end of the day... Clearly that isn't correct. I'm not saying that changing the Info.plist around will necesarily break anything - in fact it is pretty clear that SourceCode importer can probably do a very basic import on any text file. But the point is - you're taking a risk.

Question: Since you wrote an importer for python you may have an answer for the question I posted above: how to deal with files have kMDItemContentType as "dyn.*"

Don't worry about dyn.* files. They're dynamic UTI types and should not be persistent between reboots. Not sure exactly what causes them (possibly caused by files that are not matched by any UTI description). But Spotlight is smart enough to realise that the dynamic UTI type is actually mapped to a real UTI type.

[ Reply to This | # ]
Use the RichText.mdimporter instead
Authored by: ppmax on May 26, '05 07:59:18PM
Thanks for the reply. Regarding files with type dyn.*: I want to index my httpd.conf file and a few other "generic" system files. mdls /etc/httpd/httpd.conf returns:

/etc/httpd/httpd.conf -------------
kMDItemAttributeChangeDate     = 2005-05-11 08:54:05 -0700
kMDItemContentCreationDate     = 2005-03-20 15:08:49 -0800
kMDItemContentModificationDate = 2005-03-20 15:08:49 -0800
kMDItemContentType             = "dyn.ah62d4rv4ge80g55sq2"
kMDItemContentTypeTree         = ("public.data", "public.item")
kMDItemDisplayName             = "httpd.conf"
kMDItemFSContentChangeDate     = 2005-03-20 15:08:49 -0800
kMDItemFSCreationDate          = 2005-03-20 15:08:49 -0800
kMDItemFSCreatorCode           = 0
kMDItemFSFinderFlags           = 0
kMDItemFSInvisible             = 0
kMDItemFSLabel                 = 0
kMDItemFSName                  = "httpd.conf"
kMDItemFSNodeCount             = 0
kMDItemFSOwnerGroupID          = 0
kMDItemFSOwnerUserID           = 0
kMDItemFSSize                  = 38334
kMDItemFSTypeCode              = 0
kMDItemID                      = 28530
kMDItemKind                    = "Document"
kMDItemLastUsedDate            = 2005-03-20 15:08:49 -0800
kMDItemUsedDates               = (2005-03-20 15:08:49 -0800)
Provided I add /etc/httpd to the Spotlight index path list, how do I get SL to index this file? What importer will be used? AFAIK Spotlight needs a recognized extension, or a recognized file type to index. Any suggestions?

[ Reply to This | # ]
Use the RichText.mdimporter instead
Authored by: schwa on May 27, '05 02:03:01AM
From the terminal:

mdimport -d2 /etc/httpd/httpd.conf

If you get NO output it means that Spotlight _cannot_ import the file. Which means it could either have no valid mdimporter which claims to be able to understand that file - or it might not be able to index it because Spotlight has been configured not to index files in /etc

You can fix the later by modifying the hidden Spotlight config files - other hints show how to do that. Again I wouldn't recommend it (but I'm dull & boring).

If you're sure Spotlight should be able to import the file (because you have modified the config files) then you also need to write an mdimporter to import config files. ;-)

Of course you could modify SourceCode.mdimporter to handle .conf files but that will be a bit tricky.

But as a favour to you personally (because we go back so far now) I'll take my Python importer and use it to create a .conf file importer. Expect it within the next 24hours or so. Check out http://toxicsoftware.com/blog/ for progress. Feel free to continue this thread on my blog.



[ Reply to This | # ]

Use the RichText.mdimporter instead
Authored by: schwa on May 27, '05 06:31:03PM
Use the RichText.mdimporter instead
Authored by: ppmax on May 28, '05 11:18:18AM

Wow--thanks. Im downloading now and will try ASAP.

A suggestion: I know how to modify my spotlight config (/.Spotlight-V100/_rules.plist) but you might want to incude a readme describing how to modify this file to get the importer to work.

Thanks much!



[ Reply to This | # ]
Use the RichText.mdimporter instead
Authored by: schwa on May 31, '05 03:29:15PM

There's a new version online now that imports .conf, .log and .plist.



[ Reply to This | # ]
10.4: Make Spotlight index PHP files
Authored by: Guntis on Jul 10, '05 08:19:38PM

Can someone send me modified SourceCode.mdiporter for PHP indexing?
My e-mail is guntis@ [remove this] baznica.lv
Thanks in advance!
Guntis

---
I'm not really a Windows user...I just play one at work.



[ Reply to This | # ]
10.4: Make Spotlight index PHP files
Authored by: klein on Oct 05, '05 10:40:47AM
I modified the info.plist and I got some odd output when I did the reindexing command. Shoud I worry about this?

$mdimport -r /Library/Spotlight/SourceCode.mdimporter

2005-10-05 19:31:55.225 mdimport[349] Asking server to reimport files with UTIs: (
    "dyn.ah62d4rv4ge80un3p", 
    "public.objective-c-plus-plus-source", 
    "dyn.ah62d4rv4ge80u", 
    "dyn.ah62d4rv4ge80g", 
    "public.c-source", 
    "dyn.ah62d4rv4ge80g6du", 
    "dyn.ah62d4rv4ge80y2p0", 
    "dyn.ah62d4rv4ge804", 
    "dyn.ah62d4rv4ge80g22", 
    "dyn.ah62d4rv4ge80g8d2", 
    "public.c-header", 
    "dyn.ah62d4rv4ge80y2p0qe", 
    "dyn.ah62d4rv4ge80u6du", 
    "public.c-plus-plus-source", 
    "dyn.ah62d4rv4ge8045k", 
    "dyn.ah62d4rv4ge80u8d2", 
    "public.c-plus-plus-header", 
    "dyn.ah62d4rv4ge80g6a", 
    "public.objective-c-source", 
    "dyn.ah62d4rv4ge80gn3p", 
    "com.sun.java-source"
)


[ Reply to This | # ]
10.4: Make Spotlight index PHP files
Authored by: hfossli on Mar 19, '07 08:49:24AM

i got this shit when running mdimport -r /Library/Spotlight/SourceCode.mdimporter
2007-03-19 16:41:07.939 mdimport[1495] Asking server to reimport files with UTIs: (
"dyn.ah62d4rv4gq81k3p2su11uppurb2c465dsmy1a7a",
"public.objective-c-source",
"dyn.ah62d4rv4ge81a4dugu",
"dyn.ah62d4rv4ge80gn3p",
"dyn.ah62d4rv4ge80g6du",
"dyn.ah62d4rv4ge80u",
"dyn.ah62d4rv4ge80g22",
"dyn.ah62d4rv4ge81a4dyrz0a",
"dyn.ah62d4rv4ge80un3p",
"public.c-header",
"dyn.ah62d4rv4gq80c6durvy0g2pyrf106p5urb2a",
"public.c-plus-plus-header",
"com.sun.java-source",
"dyn.ah62d4rv4ge804",
"dyn.ah62d4rv4ge80g6a",
"public.objective-c-plus-plus-source",
"public.php-script",
"dyn.ah62d4rv4ge81a4by",
"dyn.ah62d4rv4ge80g8d2",
"dyn.ah62d4rv4ge80g",
"public.c-plus-plus-source",
"dyn.ah62d4rv4ge81a4dugq",
"dyn.ah62d4rv4gq81k3p2su11a4du",
"dyn.ah62d4rv4ge80u8d2",
"dyn.ah62d4rv4ge81a4bx",
"dyn.ah62d4rv4ge80y2p0qe",
"public.c-source",
"dyn.ah62d4rv4ge80u6du",
"dyn.ah62d4rv4ge80y2p0",
"dyn.ah62d4rv4ge8045k",
"dyn.ah62d4rv4ge81a4du"
)



[ Reply to This | # ]