As in my last blog I have described in details how to integrate Sphinx engine with MySQL . Now in this blog I will discuss about the configuration of sphinx.conf file for the index and how to do the searching of words from MySQL using SphinxSE. For this I have taken the example of simple document searching of text using sphinx.
Time for action – creating a basic search script:
listen: This options specifies the IP address and port that searchd will listen on. It can also specify the Unix-domain socket path. This options was introduced in v0.9.9 and should be used instead of the port (deprecated) option. If the port part is omitted, then the default port used is 9312.Examples:
listen = localhost
listen = 9312
listen = localhost:9898
listen = 192.168.1.25:4000
listen = /var/run/sphinx.s
log: Name of the file where all searchd runtime events will be logged. This is an optional setting and the default value is “searchd.log”.
query_log: Name of the file where all search queries will be logged. This is an optional setting and the default value is empty, that is, do not log queries.
max_children: The maximum number of concurrent searches to run in parallel. This is an optional setting and the default value is 0 (unlimited).
pid_file: Filename of the searchd process ID. This is a mandatory setting. The file is created on startup and it contains the head daemon process ID while the daemon is running. The pid_file becomes unlinked when the daemon is stopped.
Next step is to Create the Indexes:
We have to generate the indexes which are going to be used for searching.
Starting the Searchd Demon:
Sphinx search demon will start in the back ground and will start listening on the ports 9306 for mysql requests.
How to search the Sphinx index from MySQL:
First we have create the table which will link the sphinx index with mysql. Now login to MySQL
Now we can query the indexes and search the data against any work.
Sphinx Matching Modes:
We can use the following matching modes in sphinx for changing the search relevance .
There are the following matching modes available:
SPH_MATCH_ALL, matches all query words
SPH_MATCH_ANY, matches any of the query words
SPH_MATCH_PHRASE, matches query as a phrase, requiring perfect match
SPH_MATCH_BOOLEAN, matches query as a boolean expression
SPH_MATCH_EXTENDED, matches query as an expression in Sphinx internal query language
SPH_MATCH_EXTENDED2, an alias for SPH_MATCH_EXTENDED
SPH_MATCH_FULLSCAN, matches query, forcibly using the "full scan" mode as below. NB, any query terms will be ignored, such that filters, filter-ranges and grouping will still be applied, but no text-matching.