Installing Sphinx on Windows, simply
In this article I will try to explain how to install Sphinx on Windows, in very simple manner. So lets get started.
- Go to latest release download page, and download “Win32 binaries w/MySQL support” release. I am using Sphinx 2.0.3 version, on Vista. File name of downloaded file will be like sphinx-2.0.3-release-win32.zip.
- Unzip the file. The unzipped content will look like c:/sphinx-2.0.3-win32/sphinx-2.0.3-win32/api etc.
- Now copy/cut the c:/sphinx-2.0.3-win32/sphinx-2.0.3-win32/ inner folders and files
- Create new folder in C:/sphinx/ (for the sake of simplicity i have selected this path, you can change it)
- Paste the copied files and folders in this folder c:/sphinx/
- Create c:/sphinx/data/ and c:/sphinx/log/ folders.
- Create new text files c:/sphinx/log/query.log and c:/sphinx/log/searchd.log files. Note that files are having extension .log NOT the .log.txt or something.
- We will be using simpler and easy to configure config file for sphinx. This file is c:/sphinx/sphinx-min.conf.in
- Open c:/sphinx/sphinx-min.conf.in file in text editor and replace @CONFDIR@/ with c:/sphinx/ . There should be 5 lines where you need to replace this.
- Now provide you mysql login info by updating sql_user, sql_pass and sql_db values. This will allow to test us the index creation and searching later. Also make appropriate changes to sample index “source src1″ which are changing query and attributes.
- Open dos window by typing CMD in Run dialog and hitting enter.
- In DOS window type C: and enter
- Now type cd c:/sphinx/ . Now the command line should be looking like c:\sphinx>
- Now type this command and hit enter C:\sphinx\bin\searchd –install –config C:\sphinx\sphinx-min.conf.in –servicename SphinxSearch
- This will install the SphinxSearch as a service
- Now I am assuming that you have made changes to config file correctly.
- Now index the test index for the first time c:/sphinx/bin/indexer.exe –config C:\sphinx\sphinx-min.conf.in test1
- Now to start the service use this command on Dos window C:\sphinx\bin\searchd.exe –ntservice –config C:\sphinx\sphinx-min.conf.in –servicename SphinxSearch
- If every thing is OK then this command should show some results without errors. C:\sphinx\bin\search.exe –config C:\sphinx\sphinx.conf.in -i test1 term
- The above command will tell if the “term” is found in “test1″ index.
Now we are done and you can start using sphinx via php or any other API. You may need to start service next time before using.
My local sphinx config file looks like this, you can use it by changing your mysql login info
#
# Minimal Sphinx configuration sample (clean, simple, functional)
#
source src1
{
type = mysql
sql_host = localhost
sql_user = root
sql_pass = password
sql_db = test
sql_port = 3306 # optional, default is 3306
sql_query = \
SELECT id, name, state_id \
FROM cities
sql_attr_uint = state_id
}
index test1
{
source = src1
path = c:/sphinx/data/test1
docinfo = extern
charset_type = sbcs
}
indexer
{
mem_limit = 32M
}
searchd
{
listen = 9312
#listen = 9306:mysql41
log = c:/sphinx/log/searchd.log
query_log = c:/sphinx/log/query.log
read_timeout = 5
max_children = 30
pid_file = c:/sphinx/log/searchd.pid
max_matches = 1000
seamless_rotate = 1
preopen_indexes = 1
unlink_old = 1
workers = threads # for RT to work
}