Articles October 7, 2005 at 10:22 am

Using apple_spotlight_module in Tiger Server

Sherlock is back!

If you remember back in the day when Apple was touting Sherlock indexing for webpages, this is for you. You can now do this with Spotlight, which should yield a more consistent experience.1.Prepare Mac OS X Server for Spotlight

* By default on OS X Server, Spotlight is off. To activate spotlight, modify /etc/hostconfig:

SPOTLIGHT=-YES-

* Then, start the metadata service

sudo SystemStarter start "MetaData Search"

* Verify that indexing is on for your Volume. You can use the ‘mdutil’ command:

usage: mdutil -pE volume ...
mdutil can be used to manage the metadata stores used by Spotlight.
    -p publish metadata for the provided volumes.
    -i (on|off) set indexing status for the provided volumes.
    -E erase the master copy of the metadata stores for the provided volumes.
    -s print indexing status for the provided volumes.

mdutil -s /Volumes/Data # show the status for volume : /Volumes/Data
    /Volumes/Data:
    Status: Indexing Disabled

mdutil -i on /Volumes/Data # activate indexing for the volume : /Volumes/Data
    /Volumes/Data:
    Indexing enabled for volume.

mdutil -p /Volumes/Data # publish index for the volume : /Volumes/Data
    /Volumes/Data:
    Index published
    Server is now ready for using spotlight

2. Prepare Apache for using Spotlight

* Check the Apache configuration for Spotlight. You can activate spotlight module with Server Admin ( in the web /modules tab) or modify /etc/httpd/httpd.conf, by uncommenting the lines :

LoadModule apple_spotlight_module libexec/httpd/mod_spotlight_apple.so

AddModule mod_spotlight_apple.c

* Restart Apache with apachectl graceful or Server Admin

* Copy the file ‘/Library/WebServer/Documents/template.spotlight’ in the root directory of your website

* You can search using spotlight on your website, by adding .spotlight to the end of the url

www.mydomaine.com/.spotlight

www.mydomaine.com/fr/xserve.spotlight

* Obviously this is just a bare bones example, to really use this you would integrate the search field into your site’s html.

3. Integrating the search module directly in the webpage

* just add the HTML code to your page :

<code>
&lt;/HEAD&gt;
    &lt;BODY BGCOLOR="#FFFFFF"&gt;
    &lt;CENTER&gt;
    &lt;TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH=600&gt;
        &lt;TR&gt;
            &lt;TD&gt;
            &lt;TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0&gt;
                &lt;TR&gt;
                    &lt;TD&gt;
                    &lt;FORM ACTION=".spotlight" METHOD="post"&gt;
                    &lt;INPUT NAME="search" TYPE="text"&gt;
                    &lt;INPUT TYPE="submit" VALUE="Search"&gt;
                    &lt;!-- Limits the number of hits presented --&gt;
                    &lt;INPUT TYPE="hidden" NAME="maxhits" VALUE="100"&gt;
                    &lt;/FORM&gt;
                    &lt;/TD&gt;
                &lt;/TR&gt;
            &lt;/TABLE&gt;
            &lt;BR&gt;
            &lt;IMG SRC="grayline.gif" WIDTH=600 HEIGHT=1 ALIGN=bottom&gt;&lt;BR&gt;
            &lt;BR&gt;
            &lt;BR&gt;
            &lt;TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH=600&gt;
                &lt;TR&gt;
                    &lt;TD VALIGN=top&gt;
                    &lt;BR&gt;
                    &lt;FONT SIZE="+1" FACE="Arial" COLOR="#999999"&gt;&lt;B&gt;Spotlight Content Search Results&lt;/B&gt;&lt;/FONT&gt;
                      &lt;/TD&gt;
                      &lt;TD&gt;
                  &lt;!--Dynamic content will go here (no spaces before or after!)--&gt;
                  &lt;SPOTLIGHTOUT&gt;
                  &lt;!--End of dynamic content section--&gt;
                      &lt;/TD&gt;
                  &lt;/TR&gt;
             &lt;/TABLE&gt;
            &lt;BR&gt;
            &lt;BR&gt;
            &lt;CENTER&gt;&lt;IMG SRC="grayline.gif" WIDTH=600 HEIGHT=1 ALIGN=bottom&gt;&lt;BR&gt;
            &lt;P&gt;(c) Copyright 2004 Apple Computer, Inc.&lt;/P&gt;&lt;/CENTER&gt;
        &lt;/TD&gt;
    &lt;/TR&gt;
&lt;/TABLE&gt;
&lt;/CENTER&gt;
&lt;/BODY&gt;
&lt;/HTML&gt;
</code>

That’s just an example to get you started.

No Comments

  • One more thing I missed !

    Step 5 : make your volume index status on at every startup

    I realized today, after a reboot, that the Data volume where stands my web
    root directory had the indexing status set back to OFF.

    In order to have it fixed to ON after a reboot, use launchd or startup item with
    the command below :

    mdutil -s /Volumes/Data # show the status for volume : /Volumes/Data

    • You’re right, I missed the two lines before posting.

      Since I wrote, I used Lingon to create a launchd item for this. It does work
      perfectly …

      special thanks to the author of Ligon : Peter Borg

      http://lingon.sourceforge.net

      ——–
      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://
      http://www.apple.com/DTDs/PropertyList-1.0.dtd"&gt;
      <plist version="1.0">
      <dict>
      <key>Disabled</key>
      <true/>
      <key>Label</key>
      <string>fr.easymac.spotlight</string>
      <key>ProgramArguments</key>
      <array>
      <string>/bin/sh</string>
      <string>/usr/bin/mdutil -i on /Volumes/Data</string>
      <string>/usr/bin/mdutil -p /Volumes/Data</string>
      </array>
      <key>RunAtLoad</key>
      <true/>
      </dict>
      </plist>

Leave a reply

You must be logged in to post a comment.