Настройки sphinx + Drupal
Инсталяция
yum
yum install sphinx rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/x86_64/epel-release-5-4.noarch.rpm apt-get install sphinx
wget http://sphinxsearch.com/files/sphinx-2.0.3-release.tar.gz checkinstall
cd ./api/libsphinxclient dh_make -s -n -p libsphinxclient_2.0.3 dpkg-buildpackage
./configure
./configure --prefix=/usr --sbindir=/usr/sbin/sphinx
PPA
Repositories
deb http://ppa.launchpad.net/builds/sphinxsearch-stable/ubuntu precise main deb-src http://ppa.launchpad.net/builds/sphinxsearch-stable/ubuntu precise main
apt-key adv --recv-keys --keyserver keyserver.ubuntu.com B9D8946B16932B16
Sphinx config
drupal.conf
source source_main0
{
type = xmlpipe
xmlpipe_command = /usr/bin/wget -O - -q -t 1 http://site.com/sphinxsearch_scripts/sphinxsearch_xmlpipe.php?mode=main\&id=0\&first_nid=0\&last_nid=49999
}
source source_main1 : source_main0
{
xmlpipe_command = /usr/bin/wget -O - -q -t 1 http://site.com/sphinxsearch_scripts/sphinxsearch_xmlpipe.php?mode=main\&id=1\&first_nid=50000
}
source source_delta : source_main0
{
xmlpipe_command = /usr/bin/wget -O - -q -t 1 http://site.com/sphinxsearch_scripts/sphinxsearch_xmlpipe.php?mode=delta
}
index index_main0
{
source = source_main0
path = /var/www/vhosts/site.com/sphinxsearch/main0
docinfo = extern
morphology = stem_ru
charset_type = utf-8
charset_table = 0..9, A..Z->a..z, _, a..z, U 410..U 42F->U 430..U 44F, U 430..U 44F
min_word_len = 1
html_strip = 0
# agent = /home/user/sphinx/socket/sphinx.s
}
index index_main1 : index_main0
{
source = source_main1
path = /var/www/vhosts/site.com/sphinxsearch/main1
}
index index_join
{
type = distributed
local = index_main0
local = index_main1
local = source_delta
}
indexer
{
# mem_limit = 1024M
# write_buffer = 4M
mem_limit = 32M
}
searchd
{
#listen = /home/user/sphinx/socket/sphinx.s
#listen = localhost:3312
port = 3312
log = /var/log/sphinx/searchd.log
query_log = /var/log/sphinx/query.log
read_timeout = 5
max_children = 30
pid_file = /var/run/sphinx/searchd.pid
max_matches = 1000
seamless_rotate = 1
preopen_indexes = 1
unlink_old = 1
}
Для индексации используется XML pipe
Построение delta
/usr/bin/wget -O - -q -t 1 http://site.com/sphinxsearch_scripts/sphinxsearch_xmlpipe.php?mode=delta
Indexer server
- indexer –config /etc/sphinx/drupal.conf –all
- searchd –config /etc/sphinx/drupal.conf
- indexer –config /etc/sphinx/drupal.conf –rotate source_delta
- indexer –config /etc/sphinx/drupal.conf –merge index_main0 source_delta –rotate
- indexer –config /etc/sphinx/drupal.conf –merge index_main0 source_delta –merge-dst-range deleted 0 0
Модуль Drupal
src: http://drupal.org/project/sphinxsearch
остальные модули
sphinxsearch.xmlpipe.inc
32 битная
function sphinxsearch_ip_check_cidr($ip, $cidr) {
list($net, $mask) = explode('/', $cidr);
$ip_net = ip2long($net);
$ip_mask = ~((1 << (32 - $mask)) - 1);
$ip_ip = ip2long($ip);
$ip_ip_net = $ip_ip & $ip_mask;
#watchdog('sphinxsearch', "$ip_ip_net == $ip_net", NULL, WATCHDOG_ERROR);
return ($ip_ip_net == $ip_net);
}
32-64 битная
function sphinxsearch_ip_check_cidr($ip, $cidr) {
list($net, $mask) = explode('/', $cidr);
$ip_net = ip2long($net);
$ip_mask = ~((1 << ((PHP_INT_SIZE==8 ? 64 : 32) - $mask)) - 1);
$ip_ip = ip2long($ip);
$ip_ip_net = $ip_ip & $ip_mask;
#watchdog('sphinxsearch', "$ip_ip_net == $ip_net", NULL, WATCHDOG_ERROR);
return ($ip_ip_net == $ip_net);
}
Настройки модуля
Запуск демона
sphinx - centos
#!/bin/sh
#
# sphinx searchd Free open-source SQL full-text search engine
#
# chkconfig: - 20 80
# description: Starts and stops the sphinx searchd daemon that handles \
# all search requests.
### BEGIN INIT INFO
# Provides: searchd
# Required-Start: $local_fs $network
# Required-Stop: $local_fs $network
# Should-Start: $remote_fs
# Should-Stop: $remote_fs
# Default-Start:
# Default-Stop: 0 1 2 3 4 5 6
# Short-Description: start and stop sphinx searchd daemon
# Description: Sphinx is a free open-source SQL full-text search engine
### END INIT INFO
# Source function library.
. /etc/rc.d/init.d/functions
exec="/usr/bin/searchd"
prog="searchd"
config="/etc/sphinx/drupal.conf"
lockfile=/var/lock/subsys/searchd
start() {
[ -x $exec ] || exit 5
[ -f $config ] || exit 6
echo -n $"Starting $prog: "
# if not running, start it up here, usually something like "daemon $exec"
daemon $exec --config $config
retval=$?
echo
[ $retval -eq 0 ] && touch $lockfile
return $retval
}
stop() {
echo -n $"Stopping $prog: "
# stop it here, often "killproc $prog"
killproc $prog
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
}
restart() {
stop
start
}
reload() {
restart
}
force_reload() {
restart
}
rh_status() {
# run checks to determine if the service is running or use generic status
status $prog
}
rh_status_q() {
rh_status >/dev/null 2>&1
}
case "$1" in
start)
rh_status_q && exit 0
$1
;;
stop)
rh_status_q || exit 0
$1
;;
restart)
$1
;;
reload)
rh_status_q || exit 7
$1
;;
force-reload)
force_reload
;;
status)
rh_status
;;
condrestart|try-restart)
rh_status_q || exit 0
restart
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}"
exit 2
esac
exit $?

