Basic sphinx api setup
Actually my question seems to be very simple.
- I am using sphinx version 2.3.1 beta li>
- I cannot configure it to find my db.
- I am using a
mysql
DB with 1.57 GB of data and this is on my local server. - and I want to use with .
sphinxapi
php
As I understand it, I need to say sphinx
- Where to find data
- How to handle it
- Where to store indexes
Well, I don't know which file I should change.
I found a file called configure in the sphinx folder and I tried that and then I changed sphinx.conf.in but still I can't use . sphinx
It would be great if you could help me tweak the basic settings . sphinx
I have researched in questions, but there is no such basic question as this.
Thanks in advance.
source to share
I've seen this budding confusion a few times, so thought I'd give a slightly more detailed quick start. So, a basic introduction to get started looking for Sphinx:
Usually sphinx project files are stored in three directories: project/sphinx/etc
, project/sphinx/logs
and project/sphinx/data
. They can be changed as needed, but I am following this convention below.
Sphinx launch
After installing Sphinx on your system, you will have two executables: indexer
and searchd
. indexer
is a program that checks the configuration file and indexes the data you provide for quick access. searchd
- a background process (or daemon) that you usually want to keep running. Think of it like the Sphinx search engine. All requests from are sphinxapi
directed to searchd
, which will search the indexed data and return the record IDs in the order you specify. Examples of running both of these executables (on Linux, although in windows shouldn't be too different) are given below:
indexer -c /path/to/project/sphinx/etc/sphinx.conf --all
Specifies all sources specified in the config file. Additional options are available to index only specified sources. A detailed list of options is here .
searchd -c /path/to/project/sphinx/etc/sphinx.conf --rotate
This will initialize the daemon searchd
and deploy it in the background, where it will keep running until you kill it. This parameter rotate
allows you to keep the daemon running even if the indexes are updated in the future. You can use the switch --stop
to stop the demon. A detailed list of options is here .
Sphinx setup
This brings us to the configuration file. The config file consists of a set of configurations source
and index
together with a section searchd
used to customize the Sphinx itself. Many options can be configured here, but the basic one sphinx.conf
(usually the sphinx.conf.dist file found in the sphinx install folder) is a bit overwhelming at first. I'm just mentioning a few basic configuration options to get started. I assume 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 configuration of searchd, defining features such as writing logs as well as a file .pid
to lock. The search daemon listens on the port 9312
to which it sphinxapi
forwards requests 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 data source. This indexer
will run the provided query and index the results. id
is taken as a key since it is an integer field and does not explicitly mention what it is (as opposed to a field status
). Since text_field
is a text field (duh!), The indexes are sphinx, which is implicit for full text search. We also specify that status
is an integer field that we can use later to filter the results when doing a 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 be used for searches. A data source is provided. Many options are available to tailor the results to your needs. I have given just one example in which we indicate that searchd
the synchronization algorithm should be used to match requests. The details of all available options can be gleaned from reading:
This is in no way close to detailing, but I hope it helps you get started ...
source to share