这两天在做sphinx全文索引的项目,研究了两天了终于把它搞定了,下面来总结一下
1.安装sphinx(我这里用的是macOS,linux后文使用的大部分命令都兼容)
mkdir /usr/local/sphinx
cd /usr/local/spinx
wget http://sphinxsearch.com/files/sphinx-2.2.11-release.tar.gz
tar -zvxf sphinx-2.2.11-release.tar.gz
cd sphinx-2.2.11
./configure
sudo make && make install
测试是否安装成功
searchd -h //有提示即为成功
安装过程碰到的错误
configuring Sphinx
checking for CFLAGS needed for pthreads… none
checking for LIBS needed for pthreads… -lpthread
checking for pthreads… found
checking whether to compile with MySQL support… yes
checking for mysql_config… mysql_config
checking for mysql_real_connect… no
checking for mysql_real_connect… no
checking MySQL include files… configure: error: missing include files.
**
ERROR: cannot find MySQL include files.
解决办法:sudo apt-get install libmysql++
2.sphinx.conf配置(相关配置参数详见sphinx官网)
# Minimal Sphinx configuration sample (clean, simple, functional)
#
source main_src
{
type = mysql
sql_host = 192.168.1.221
sql_user = root
sql_pass =root.remote
sql_db = caiban
sql_port = 3306 # optional, default is 3306
sql_sock =/tmp/mysql.scok
sql_query_pre =SET NAMES utf8
sql_query_pre =SET SESSION query_cache_type=OFF
sql_query_pre =replace into sph_counter select 1,max(id) from register_enterprise_extends
sql_query = \
SELECT id,company_name,trademark,legal_person_name, UNIX_TIMESTAMP(created_at) AS created_at,reg_address,reg_number,business_scope,linkman,reg_organs,operating_period,views,reg_capital FROM register_enterprise_extends where id<=(select max_doc_id from sph_counter where counter_id=1)
sql_attr_uint =id
sql_field_string =company_name
sql_field_string =trademark
sql_field_string =legal_person_name
sql_attr_timestamp =created_at
sql_field_string =reg_address
sql_field_string =reg_number
sql_field_string =business_scope
sql_field_string =reg_organs
sql_field_string =operating_period
sql_field_string =reg_capital
sql_field_string =views
}
source delta_src: main_src{
sql_ranged_throttle=100
sql_query_pre=SET NAMES utf8
sql_query_pre=SET SESSION query_cache_type=OFF
sql_query= SELECT id,company_name,trademark,legal_person_name, UNIX_TIMESTAMP(created_at) AS created_at,reg_address,reg_number,business_scope,linkman,reg_organs,operating_period,views,reg_capital FROM register_enterprise_extends where id>(select max_doc_id from sph_counter where counter_id=1)
sql_attr_uint =id
sql_field_string =company_name
sql_field_string =