Introduction:

Sphinx  is a full-text search engine, it runs as a daemon and serves to requests of client applications. Client applications need to access Sphinx daemon via the native SphinxAPI, for which libraries are available in almost all popular languages like PHP, Perl, Ruby, Java, C# etc.
Applications can access Sphinx search daemon (searchd) using any of the three different access methods: a) via native search API (SphinxAPI), b) via Sphinx own implementation of MySQL network protocol (using a small SQL subset called SphinxQL), or c) via MySQL server with a pluggable storage engine (SphinxSE).

Official native SphinxAPI implementations for PHP, Perl, Ruby, and Java are included within the distribution package.

Sphinx Features:

  • High indexing and searching performance.
  • Advanced result set post-processing (SELECT with expressions, WHERE, ORDER BY, GROUP BY etc over text search results).
  • Sphinx has high indexing speed (up to 10-15 MB/sec per core on an internal benchmark).
  • Sphinx has high search speed (up to 150-250 queries/sec per core against 1,000,000 documents, 1.2 GB of data on an internal benchmark).

How To Use :

1. Download “Win32 binaries w/MySQL support” here: http://sphinxsearch.com/downloads/beta/

2. Unzip the zip file to C:\Sphinx. This directory should now include a few files, such as sphinx.conf.in, and subdirectories, such as api and bin.

3. Add the subdirectories data and log.

4. Open C:\Sphinx\sphinx.conf.in in a text editor.

5. Change the settings sql_user and sql_pass to match your MySQL installation.

6. Find and replace all occurrences of @CONFDIR@/ with C:\Sphinx\, at least in the uncommented lines.

7. Find and replace all occurrences of forward slash (/) with backslash (\) in these same lines. For example @CONFDIR@/data/test1 becomes C:\Sphinx\data\test1.

8. Start cmd.exe as an administrator.

9. Go to your MySQL installation directory, for example enter cd c:\xampp\mysql.

10. Create the test database and fill it with data by entering:

mysql -u [youruser] -p < c:\Sphinx\bin\example.sql (replace [youruser] with your user name).

11. Enter cd c:\Sphinx\bin.

12. Index the test database by entering indexer.exe –config c:\Sphinx\sphinx.conf test1.

13. Install Sphinx as a service by entering:

searchd.exe –install –config c:\sphinx\bin\sphinx.conf –servicename SphinxSearch

14. Start the service:

>Click on start , right click on “Computer”.
->Click on “Manage”.
->Click on “Services and Applications”.
->Click on “Services”
->Then start the “Sphinx Service”.

15. Test the search by entering: search.exe –config c:\sphinx\sphinx.conf test. This should result in some matches for the search term “test”.

16. Copy the Sphinx Search PHP API from C:\Sphinx\api\sphinxapi.php to your site’s HTML directory, for example C:\xampp\htdocs\[yoursite]\sphinxapi.php.

17. Example

<?php
mysql_connect("localhost", "root", [yourpassword]);
mysql_select_db("test");
require_once('sphinxapi.php');
$s = new SphinxClient;
$s->setServer("127.0.0.1", 9312); // NOT "localhost" under Windows 7!
$s->setMatchMode(SPH_MATCH_EXTENDED2);
$s->SetLimits(0, 25);
$result = $s->Query("test");
if ($result['total'] > 0) {
echo 'Total: ' . $result['total'] . "<br>\n";
echo 'Total Found: ' . $result['total_found'] . "<br>\n";
echo '<table>';
echo '<tr><td>No.</td><td>ID</td><td>Group ID</td><td>Group ID 2</td><td>Date Added</td><td>Title</td><td>Content</td></tr>';
foreach ($result['matches'] as $id => $otherStuff) {
$row = mysql_fetch_array(mysql_query("select * from documents where id = $id"));
extract($row);
++ $no;
echo "<tr><td>$no</td><td>$id</td><td>$group_id</td><td>$group_id2</td><td>$date_added</td><td>$title</td><td>$content</td></tr>";
}
echo '</table>';
} else {
echo 'No results found';
}
?>

18. References :

http://sphinxsearch.com/docs/2.0.1/
http://sphinxsearch.com/forum/view.html?id=2972
http://www.crankberryblog.com/2011/intalling-sphinx-on-wamp-localhost-windows
http://sphinxsearch.com/forum/view.html?id=4986