闲情逸致 http://EZ38.com
分类: LINUX
2010-02-21 15:16:59
Quick Sphinx usage tour
All the example commands below assume that you installed Sphinx in
/usr/local/sphinx
, sosearchd
can be found in/usr/local/sphinx/bin/searchd
.To use Sphinx, you will need to:
Create a configuration file.
Default configuration file name is
sphinx.conf
. All Sphinx programs look for this file in current working directory by default.Sample configuration file,
sphinx.conf.dist
, which has all the options documented, is created byconfigure
. Copy and edit that sample file to make your own configuration: (assuming Sphinx is installed into/usr/local/sphinx/
)
$ cd /usr/local/sphinx/etc
$ cp sphinx.conf.dist sphinx.conf
$ vi sphinx.confSample configuration file is setup to index
documents
table from MySQL databasetest
; so there'sexample.sql
sample data file to populate that table with a few documents for testing purposes:
$ mysql -u test < /usr/local/sphinx/etc/example.sql
Run the indexer to create full-text index from your data:
$ cd /usr/local/sphinx/etc
$ /usr/local/sphinx/bin/indexerQuery your newly created index!
To query the index from command line, use
search
utility:
$ cd /usr/local/sphinx/etc
$ /usr/local/sphinx/bin/search testTo query the index from your PHP scripts, you need to:
Run the search daemon which your script will talk to:
$ cd /usr/local/sphinx/etc
$ /usr/local/sphinx/bin/searchdRun the attached PHP API test script (to ensure that the daemon was succesfully started and is ready to serve the queries):
$ cd sphinx/api
$ php test.php testInclude the API (it's located in
api/sphinxapi.php
) into your own scripts and use it.Happy searching!