Reputation: 79
Actually my question seems to be very basic.
mysql
DB with 1.57 GB data and this is on my server localhost.sphinxapi
with php
.As much as I figured out, I have to Tell sphinx
Well, I don't know which file should I change.
I found a file named configure in sphinx folder, and I tried this, and then I changed sphinx.conf.in but still I can't use sphinx
.
It would be great if you help me to configure sphinx
basic setting.
I researched in questions but there's not a basic question like this.
Thanks in advance.
Upvotes: 3
Views: 287
Reputation: 1274
I have seen this beginner confusion a few times so thought I would give a bit more detailed quick start. So, a basic intro to start using Sphinx search:
Usually, sphinx project files are stored under three directories: project/sphinx/etc
, project/sphinx/logs
and project/sphinx/data
. These can be modified as needed but I am following this convention below.
After you install Sphinx on your system, you will have two executables: indexer
and searchd
. indexer
is the program that checks the configuration file and indexes the data that you have specified for quick access. The searchd
is a background process (or daemon) that you will usually want to keep running. Think of this as the action Sphinx search engine. All queries from the sphinxapi
are routed to the searchd
which will perform searches against the indexed data and return ids of the records in the order you have specified. Examples of running both these executables (in linux, though on windows it shouldn't be too different) are given below:
indexer -c /path/to/project/sphinx/etc/sphinx.conf --all
This indexes all the sources specified in the configuration file. More options are available for indexing only specified sources. Detailed listing of options here.
searchd -c /path/to/project/sphinx/etc/sphinx.conf --rotate
This initializes the searchd
daemon and forks it to background where it will continue to run until you kill it. The rotate
option allows you to keep the daemon running even while you update the indexes in future. You can use the --stop
switch to stop the daemon. Detailed listing of options here.
This brings us to the configuration file. The configuration file consists of a collection of source
and index
configurations along with a searchd
section used to configure sphinx itself. There are many options to be configured here but the basic sphinx.conf
(usually a sphinx.conf.dist file found at the sphinx installation folder) file is a bit overwhelming at first. I am just mentioning a few of the basic configuration options that are required to get you started. I am assuming that you are using MySQL
, but this should be easily adaptable to any data provider.
searchd {
/* Define your file paths. */
log = /path/to/project/sphinx/logs/searchd.log
query_log = /path/to/project/sphinx/logs/query.log
pid_file = /path/to/project/sphinx/logs/searchd.pid
/* Listen on port 9312 (This is the default port) */
listen = localhost:9312
}
This is the basic searchd configuration specifying things like where to write the logs as well as a .pid
file to lock. The search daemon listens on port 9312
to which sphinxapi
forwards it's queries by default.
source text_search{
/* Data provider details */
type = mysql
sql_host = localhost
sql_user = sql_user_name
sql_pass = sql_pass_word
sql_db = my_db_name
/* The query used to index the data. A very basic example... */
sql_query = SELECT id, text_field, status FROM text_search
sql_attr_uint = status
}
This is the source of data. Here, the indexer
will run the provided query and index the results. id
is taken as the key as it is an integer field and not explicitly mentioned what it is (unlike the status
field). Since text_field
is a text field (duh!), sphinx indexes that for full-text searching implicitly. We also specify that status
is an integer field that we can use later for filtering the results when we perform search.
index text_search_index{
/* The data source that we have defined above. */
source = text_search
/* The path to store the index data/cache */
path = /path/to/project/data/text_search
/* Use stemming while searching */
morphology = stem_en
}
This defines the details of the index that searchd
will use for searching. The source of the data is provided. Many options are available to tailor the results to your needs. I have provided just one example where we specify that searchd
has to use a stemming algorithm to match queries. Details of all available options can be gleaned by reading from:
This is in no way close to being detailed, but I hope this will get you started...
Upvotes: 4
Reputation: 21091
If you've installed sphinx ok, just run
indexer
(with no arguments)
... it should tell you where its looking for the config file.
Copy sphinx.conf.dist to sphinx.conf
at that location. (not the .in file) Then edit as required.
Upvotes: 1