Build Search Application for Zen Cart and osCommerce using Sphinx Full Text Search Engine
1, Download Sphinx from http://www.sphinxsearch.com/downloads.html
wget http://www.sphinxsearch.com/downloads/sphinx-0.9.9-rc1.tar.gz
gunzip sphinx-0.9.9-rc1.tar.gz
tar xvf sphinx-0.9.9-rc1.tar
2, Start search engine
mkdir -p /var/log/searchd
/home/sphinx/sphinxsearch/bin/searchd –config /home/sphinx/sphinxsearch/etc/sphinx.conf
Sphinx 0.9.9-rc1 (r1566)
Copyright (c) 2001-2008, Andrew Aksyonoff
using config file ‘/home/sphinx/sphinxsearch/etc/sphinx.conf’…
listening on all interfaces, port=3312
ps -ef |more to check if searchd is running.
3, Write PHP code for search:
< ?php
include('/home/sphinx/sphinx-0.9.9-rc1/api/sphinxapi.php');
$cl = new SphinxClient();
$cl->SetServer( “250.20.2.1″, 3312 );
$cl->SetMatchMode( SPH_MATCH_ANY );
//$cl->SetFilter( ‘model’, array( 3 ) );
$result = $cl->Query( ‘akt’, ‘labsupply_indx’ );
if ( $result === false ) {
echo “Query failed: ” . $cl->GetLastError() . “.\n”;
}
else {
if ( $cl->GetLastWarning() ) {
echo “WARNING: ” . $cl->GetLastWarning() . ”
“;
}
if ( ! empty($result["matches"]) ) {
foreach ( $result["matches"] as $doc => $docinfo ) {
echo “$doc\n”;
}
print_r( $result );
}
}
exit;
?>