From Electron Cloud
Revision as of 18:18, 27 September 2005 by Ecloud (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Here's how to search uploaded files with swish++ (but it's been a while since I did this, so can't guarantee this is all there is to it):

if ( strstr($searchnamespaces, "6") )
{
    $mediaResults = popen("/usr/local/bin/search -c /usr/local/etc/swish++.conf -i /var/lib/swish/wiki-media.index $this->mRawtext", "r");
    $mediaResultCount = 0;
    # throw away the initial comment
    $outline = fgets($mediaResults);
    while (!feof($mediaResults))
    {
		$outline = fgets($mediaResults);
		list($rank, $fname, $fsize, $ftitle) = explode(" ", $outline, 4);
		if ($rank)
		{
			if (!$mediaResultCount)
			{
					$wgOut->addHTML("<H2>Uploaded media matches</H2><OL>");
			}
			$wgOut->addHTML("<LI><a href=" . substr($fname, 19) . ">$ftitle</a> <font size=-2>($fsize bytes) Relevance: $rank</font>");
			$mediaResultCount++;
		}
    }
    $wgOut->addHTML("</OL>");
    pclose($mediaResults);
    if (!$mediaResultCount)
    {
		    $wgOut->addHTML("<H2>No uploaded media matches</H2>");
    }
}

Obviously /usr/local/etc/swish++.conf must exist, and then you use "index" (one of the swish programs, which has an arrogantly generic name :-) to build /var/lib/swish/wiki-media.index. /usr/local/etc/swish++.conf has all the magic rules about how to extract "words" from every kind of document. Alas I seem to have lost this file. Sigh. I'll do it again someday...