Installation Guide

Contents

Getting Started with Sphinx on Windows

• Download • Install Sphinx as a service • Add sample data • Make changes to sphinx.conf.in • Index your data • Search • MySQL protocol support

Getting Started with Sphinx on Linux

• Download • Install • up data source • Index • Search • MySQL Protocol Support

Thanks for searching with Sphinx!

We want the installation process to be painless. If this guide leaves you with unanswered questions, please tell us on the forum (http://sphinxsearch.com/forum/). Or, you could even tweet at us (@sphinxsearch).

Happy Sphinxing!

Sphinxsearch.com 1 (888) 333-1345 Getting Started on Windows Download

Visit the Sphinx Download page (http://sphinxsearch.com/downloads) to get the pre- compiled 32 or 64-bit binary packages. To compile Sphinx yourself, just grab the source.

Unzip the binary to a folder. Let's assume you used C:\Sphinx

Install Sphinx as a service

Open a command line with administrator rights and type:

C:\Sphinx\bin> C:\Sphinx\bin\searchd --install --config C:\Sphinx\sphinx.conf.in --servicename SphinxSearch

**the SphinxSearch service has not started at this point (no index has been setup and so there is no index to serve). You will get an error message if you try to start Sphinx now.

Add sample data

We'll use MySQL for our data source.

Let's add some sample data:

CREATE TABLE documents ( id INTEGER PRIMARY KEY NOT NULL AUTO_INCREMENT, group_id INTEGER NOT NULL, group_id2 INTEGER NOT NULL, date_added DATETIME NOT NULL, title VARCHAR(255) NOT NULL, content TEXT NOT NULL ); REPLACE INTO documents ( id, group_id, group_id2, date_added, title, content ) VALUES ( 1, 1, 5, NOW(), 'test one', 'this is my test document number one. also checking search within phrases.'), ( 2, 1, 6, NOW(), 'test two', 'this is my test document number two'), ( 3, 2, 7, NOW(), 'another doc', 'this is another group'), ( 4, 2, 8, NOW(), 'doc number four', 'this is to test groups');

Sphinxsearch.com 1 (888) 333-1345 In C:\Sphinx you will find the Sphinx configuration file (sphinx.conf.in). It's a plain text file that can be opened with any text editor. The file will give you a sample index, along with comments for most configuration options.

There's also sphinx-min.conf.in, which is the same configuration without comments.

Make changes to sphinx.conf.in

Edit the configuration options for connecting to MySQL:

sql_host = localhost sql_user = test sql_pass = sql_db = test sql_port = 3306

Replace all occurrences of @CONFDIR@ with the location of the folder where you will be keeping the index files and logs.

You then need to create two folders in this directory. Name them “ data ” and “log”.

You're done editing the configuration.

Index your data

Like this:

C:\Sphinx\bin> C:\Sphinx\bin\indexer --config C:\Sphinx\sphinx.conf.in test1

If you add new records to the example table, you will need to reindex the data. The only difference from the example above is that you will need to add --rotate at the end.

Now you can start the SphinxSearch service from the services console.

Search

In C:\Sphinx\ you can find the API libraries for various languages as well as a sample script. If you're using PHP, check test.. This script presents basic search features and it's a good way to start learning to use the API.

Sphinxsearch.com 1 (888) 333-1345 Simply run:

C:\Sphinx\api> C:\path\to\php.exe test.php test

Or, try this:

SetServer ( "localhost", 9312); $cl->SetArrayResult ( true ); $res = $cl->Query ( $q, "*" ); if($res!=false) { print “Query '$q' retrieved $res[total] of $res[total_found] matches in $res[time] sec.\n”; if($res[“total_found'] >0) { $n = 1; foreach ($res[“matches”] as $docinfo) { print “$n. doc_id=$docinfo[id], weight=$docinfo[weight] \n”; $n++; } } }

MySQL protocol support

Sphinx supports MySQL protocol. So, to connect to Sphinx, you can use the MySQL extensions with your favorite languages. In the case of PHP, use mysqli or PDO_MySQL. Or, just use the MySQL command-line tool on the Sphinx port (9306) to run some queries.

Sphinxsearch.com 1 (888) 333-1345 Getting Started on Linux Download

Visit the Sphinx download page and grab the pre-compiled binary package. Or, just grab the source and compile it yourself.

Learn more: http://sphinxsearch.com/docs/current.html#compiling-from-source

Install

For Ubuntu, there is an official PPA (https://launchpad.net/~builds/ +archive/ubuntu/sphinxsearch-rel22).

The binary packages can be installed just as any deb or rpm package.

rpm -Uvh sphinx-2.0.6-1.rhel6.x86_64.rpm dpkg -i sphinxsearch_2.0.6-release-0ubuntu11~lucid_amd64.deb

The binary packages will install:

• binaries in /usr/bin • a configuration directory in /etc (named either 'sphinxsearch' or 'sphinx', depending on the package) • a service called searchd • a logrotate entry • folders for log files in /var/log • a folder for data in /var/lib • main files • docs and in /usr/share/sphinxsearch (deb versions) or /usr/share/sphinx & /usr/share/doc/sphinx-2.0.x (rpm versions).

**After installing, don't start the service... it will fail! We still need to build an index.**

Sphinxsearch.com 1 (888) 333-1345 Set up data source

MySQL is a very common data source. Let's use it.

Add some sample data:

CREATE TABLE documents ( id INTEGER PRIMARY KEY NOT NULL AUTO_INCREMENT, group_id INTEGER NOT NULL, group_id2 INTEGER NOT NULL, date_added DATETIME NOT NULL, title VARCHAR(255) NOT NULL, content TEXT NOT NULL ); REPLACE INTO documents ( id, group_id, group_id2, date_added, title, content ) VALUES ( 1, 1, 5, NOW(), 'test one', 'this is my test document number one. also checking search within phrases.' ), ( 2, 1, 6, NOW(), 'test two', 'this is my test document number two' ), ( 3, 2, 7, NOW(), 'another doc', 'this is another group' ), ( 4, 2, 8, NOW(), 'doc number four', 'this is to test groups' );

In /etc/sphinx (or /etc/sphinxsearch ) you have a file called sphinx.conf . It's a plain text file. Open it with any text editor.

The file will give you a sample index. In the documentation folder you can find the same file, but with comments on every option. In sphinx.conf, edit the MySQL settings for your index.

Configure the data source:

sql_host = localhost sql_user = test sql_pass = sql_db = test sql_port = 3306 Index

Run indexer:

$ sudo -u sphinx indexer test1

If you add new records to the example table, you will need to reindex the data before you can search it. The command will be the same as you see above, the only difference is that we need to add --rotate at the end.

Sphinxsearch.com 1 (888) 333-1345 Search

Start searchd:

$ service searchd start

In the API folder you can find the API libraries for various languages as well as a sample script. If you're using PHP, check test.php. This script presents basic search features and it's a good way to start learning to use the API.

To try the test.php we've included, just run:

$ php test.php test

Or, try this:

SetServer ( "localhost", 9312); $cl->SetArrayResult ( true ); $res = $cl->Query ( $q, "*" ); if($res!=false) { print "Query '$q' retrieved $res[total] of $res[total_found] matches in $res[time] sec.\n"; if($res["total_found"] >0) { $n = 1; foreach ($res["matches"] as $docinfo) { print "$n. doc_id=$docinfo[id], weight=$docinfo[weight] \n"; $n++; } } }

MySQL Protocol Support

Sphinx supports MySQL protocol. So, to connect to Sphinx, you can use the MySQL extensions with your favorite languages. In the case of PHP, use mysqli or PDO_MySQL. Or, just use the MySQL command-line tool on the Sphinx port (9306) to run some queries.

Sphinxsearch.com 1 (888) 333-1345 Thanks for using Sphinx!

Any questions?

Find us on twitter: @sphinxsearch

Get help on the forum: http://sphinxsearch.com/forum/

Read the documentation: http://sphinxsearch.com/docs/

See these tutorials (from our blog): http://sphinxsearch.com/blog/category/tutorials/

Want support from the Sphinx team?

Contact us for information: http://sphinxsearch.com/about/contact/

Sphinxsearch.com 1 (888) 333-1345