PHP implementation of keyword full-text search Sphinx and Chinese word segmentation Coreseek installation and configuration

1. Requirements

  The article that contains the search term in the article title or classification (even article content) is displayed according to the weight of the frequency of the search term.

2. Environment

  Nginx + PHP + Mysql (system Centos7).

3. Installation

  1. Installation dependencies

yum  -y  install  make  gcc  gcc-c++  libtool  autoconf  automake  imake  mariadb  mariadb-server  mariadb-devel libxml2-devel expat-devel

  2. Download the software package

git clone https://github.com/wanqianworld/coreseek4.1.git
cd coreseek4.1 #Enter the directory after downloading

  3. Unzip coreseek

tar -xzf coreseek-4.1-beta.tar.gz

  4. Install mmseg

cd  coreseek-4.1-beta/mmseg-3.2.14
./bootstrap
./configure --prefix=/usr/local/mmseg3
make && make install

  5. Install coreseek

  5.1. Modify configuration

cd ../csft-4.1 
vim configure .ac
AM_INIT_AUTOMAKE([-Wall -Werror foreign])
修改为
AM_INIT_AUTOMAKE([-Wall foreign])

  5.2. Download the software

yum  -y  install  patch

  5.3. Patching

patch -p1 </yourpath/sphinx/sphinxexpr.cpp-csft-4.1-beta. patch 
input:
 /yourpath/sphinx/coreseek-4.1-beta/csft-4.1/src/sphinxexpr.cpp

  5.4. Installation

sh  buildconf.sh
./configure  --prefix=/usr/local/coreseek  --without-unixodbc  --with-mmseg  --with-mmseg-includes=/usr/local/mmseg3/include/mmseg/  --with-mmseg-libs=/usr/local/mmseg3/lib/  --with-mysql
make  &&  make install

  6.1. Test Chinese word segmentation

../testpack/ cd 
/ usr / local / mmseg3 / bin / MMSEG -d / usr / local / mmseg3 / etc var /test/test.xml # test Chinese word

 

   6.2. Create Index

/usr/local/coreseek/bin/indexer  -c  etc/csft.conf  --all

 

   6.3. Search test

/ usr / local / coreseek / bin / search -c etc / csft.conf Li Yanhong

 

  7.php connect sphinx

../csft-4.1/api/libsphinxclient/ cd # enter the directory 

aclocal 
libtoolize - Force 
automake --add- Missing 
autoconf 
autoheader 
the make Clean
 ./configure --prefix = / usr / local / sphinxclient 
the make   && the make install   # compilation 

cd   ../../../../ # back to the package directory 
tar -xzf sphinx-1.3.0.tgz   # decompression 
yum -y install PHP PHP-devel # install-devel PHP 

cd sphinx -1.3.0   # Install 
phpize
 ./configure --with-php-config = / usr / bin / php-config --with-sphinx = / usr / local /sphinxclient
make && make install

  7.1. Open php-sphinx extension

vim / etc / php. ini 
add at the end: 
[sphinx] 
extension = sphinx.so

  8. Test

  8.1. Add test data

mysql  -uroot  -p123456  <  /usr/local/coreseek/etc/example.sql

  8.2 Copy configuration file

cp  /usr/local/coreseek/etc/sphinx.conf.dist  /usr/local/coreseek/etc/csft.conf
cp  /home/lee/sphinx/coreseek-4.1-beta/mmseg-3.2.14/data/*  /usr/local/mmseg3/etc/

  8.3. Modify configuration file

vim /usr/local/coreseek/etc/csft.conf
source src1
{
type            = mysql
sql_host        = 127.0.0.1
sql_user        = root
sql_pass        = 123456
sql_db          = test
sql_port        = 3306  # optional, default is 3306
sql_query_pre = SET NAMES utf8
sql_sock = /var/lib/mysql/mysql.sock
sql_query       = \
    SELECT id, group_id, UNIX_TIMESTAMP(date_added) AS date_added, title, content \
    FROM documents
sql_attr_uint       = group_id
sql_attr_timestamp  = date_added
sql_ranged_throttle = 0
sql_query_info_pre = SET NAMES utf8
sql_query_info      = SELECT * FROM documents WHERE id=$id
}
source src1throttled : src1
{
sql_ranged_throttle = 100
}
index test1
{
source          = src1
path            = /usr/local/coreseek/var/data/test1
docinfo         = extern
mlock           = 0
morphology      = none
min_word_len        = 1
html_strip      = 0
charset_dictpath = /usr/local/mmseg3/etc/
charset_type        = zh_cn.utf-8
}
indexer
{
mem_limit       = 128M
}
searchd
{
listen          = 9312
listen          = 9306:mysql41
log         = /usr/local/coreseek/var/log/searchd.log
query_log       = /usr/local/coreseek/var/log/query.log
read_timeout        = 5
client_timeout      = 300
max_children        = 30
pid_file        = /usr/local/coreseek/var/log/searchd.pid
max_matches     = 1000
seamless_rotate     = 1
preopen_indexes     = 1
unlink_old      = 1
mva_updates_pool    = 1M
max_packet_size     = 8M
max_filters     = 256
max_filter_values   = 4096
max_batch_queries   = 32
workers         = threads # for RT to work
}

  8.4. Copying binary files

cp  /usr/local/coreseek/bin/*  /usr/bin/

  8.5 Generate Index

indexer  --rotate  --all

  8.6. Starting the service

searchd

  8.7. Stop service

searchd  --stop

  9. Test

  Write a test script:

vim test.php
<?php
$sphinx = new SphinxClient();
$sphinx->SetServer("127.0.0.1",9312);
$sphinx->SetMatchMode(SPH_MATCH_ALL);
$sphinx->SetLimits(0, 20, 1000);
$sphinx->SetArrayResult(true);
$result = $sphinx -> query("one","test1");
var_dump($result);

  Run the script:

php test.php

 

Guess you like

Origin www.cnblogs.com/yuanwanli/p/12683351.html