Warning: date(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected the timezone 'UTC' for now, but please set date.timezone to select your timezone. in /home/www/domains/hppgallery_com/design/defaulttheme/tpl/pagelayouts/main.php on line 59

Warning: date(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected the timezone 'UTC' for now, but please set date.timezone to select your timezone. in /home/www/domains/hppgallery_com/design/defaulttheme/tpl/pagelayouts/main.php on line 59
Tuesday, February 21, 2017
 

Sphinx configuration tutorial

This page describes how to implement Sphinx search engine in gallery. This information is a little bit old because delay index was introduced.

 

Sphinx configuration

This section describes how to setup sphinx in HPPG. Sphinx index is based on gallery image view. "lh_gallery_sphinx_search_view" database view

Search index view creating

There are two types of views

  1. Standard view
  2. view used for extended color search

What view to create depends on what search by color quality you want.

Sphinx index configuration

  • <host> - should be changed to mysql host. Etc. Localhost
  • <username> - database username
  • <password> - database username password
  • <database> - database name

Source configuration for first case

source anifofsrc
{
	type					= mysql
	sql_host				= <host>
	sql_user				= <username>
	sql_pass				= <password>
	sql_db					= <database>
	sql_port				= 3306	# optional, default is 3306

	sql_query				= \
		SELECT * FROM sphinxseearch

	sql_query_info			= SELECT * FROM lh_gallery_images WHERE id=$id
	sql_query_post			= DELETE FROM lh_gallery_images_delta
	
	sql_attr_uint   = pid
	sql_attr_uint   = hits
	sql_attr_uint   = mtime
	sql_attr_uint   = comtime
	sql_attr_uint   = rtime
	sql_attr_uint   = pic_rating
	sql_attr_uint   = votes
	sql_attr_uint   = pwidth
	sql_attr_uint   = pheight
	sql_attr_uint   = album_id
}

Source configuration for second case

source anifofsrc
{
	type					= mysql
	sql_host				= <host>
	sql_user				= <username>
	sql_pass				= <password>
	sql_db					= <database>
	sql_port				= 3306	# optional, default is 3306

	sql_query				= \
		SELECT * FROM lh_gallery_sphinx_search_view

	sql_query_info			= SELECT * FROM lh_gallery_sphinx_search_view WHERE id=$id
	sql_query_post			= DELETE FROM lh_gallery_images_delta
	
	sql_attr_uint   = pid
	sql_attr_uint   = hits
	sql_attr_uint   = mtime
	sql_attr_uint   = comtime
	sql_attr_uint   = rtime
	sql_attr_uint   = pic_rating
	sql_attr_uint   = votes
	sql_attr_uint   = pwidth
	sql_attr_uint   = pheight
	sql_attr_uint   = album_id
	
	sql_attr_uint   = pld1
    sql_attr_uint   = pld2
    sql_attr_uint   = pld3
    sql_attr_uint   = pld4
    sql_attr_uint   = pld5
    sql_attr_uint   = pld6
    sql_attr_uint   = pld7
    sql_attr_uint   = pld8
    sql_attr_uint   = pld9
    sql_attr_uint   = pld10
    sql_attr_uint   = pld11
    sql_attr_uint   = pld12
    sql_attr_uint   = pld13
    sql_attr_uint   = pld14
    sql_attr_uint   = pld15
    sql_attr_uint   = pld16
    sql_attr_uint   = pld17
    sql_attr_uint   = pld18
    sql_attr_uint   = pld19
    sql_attr_uint   = pld20
    sql_attr_uint   = pld21
    sql_attr_uint   = pld22
    sql_attr_uint   = pld23
    sql_attr_uint   = pld24
    sql_attr_uint   = pld25
    sql_attr_uint   = pld26
    sql_attr_uint   = pld27
    sql_attr_uint   = pld28
    sql_attr_uint   = pld29
    sql_attr_uint   = pld30
    sql_attr_uint   = pld31
    sql_attr_uint   = pld32
    sql_attr_uint   = pld33
    sql_attr_uint   = pld34
    sql_attr_uint   = pld35
    sql_attr_uint   = pld36
    sql_attr_uint   = pld37
    sql_attr_uint   = pld38
    sql_attr_uint   = pld39
    sql_attr_uint   = pld40
    sql_attr_uint   = pld41
    sql_attr_uint   = pld42
    sql_attr_uint   = pld43
    sql_attr_uint   = pld44
    sql_attr_uint   = pld45
    sql_attr_uint   = pld46
    sql_attr_uint   = pld47
    sql_attr_uint   = pld48
    sql_attr_uint   = pld49
    sql_attr_uint   = pld50
    sql_attr_uint   = pld51
    sql_attr_uint   = pld52
    sql_attr_uint   = pld53
    sql_attr_uint   = pld54
    sql_attr_uint   = pld55
    sql_attr_uint   = pld56
    sql_attr_uint   = pld57
    sql_attr_uint   = pld58
    sql_attr_uint   = pld59
    sql_attr_uint   = pld60
    sql_attr_uint   = pld61
    sql_attr_uint   = pld62
    sql_attr_uint   = pld63
    sql_attr_uint   = pld64
    sql_attr_uint   = pld65
    sql_attr_uint   = pld66
    sql_attr_uint   = pld67
    sql_attr_uint   = pld68
    sql_attr_uint   = pld69
    sql_attr_uint   = pld70
    sql_attr_uint   = pld71
    sql_attr_uint   = pld72
    sql_attr_uint   = pld73
    sql_attr_uint   = pld74
    sql_attr_uint   = pld75
    sql_attr_uint   = pld76
    sql_attr_uint   = pld77
    sql_attr_uint   = pld78
    sql_attr_uint   = pld79
    sql_attr_uint   = pld80
    sql_attr_uint   = pld81
    sql_attr_uint   = pld82
    sql_attr_uint   = pld83
    sql_attr_uint   = pld84
    sql_attr_uint   = pld85
    sql_attr_uint   = pld86
    sql_attr_uint   = pld87
    sql_attr_uint   = pld88
    sql_attr_uint   = pld89
    sql_attr_uint   = pld90
    sql_attr_uint   = pld91
    sql_attr_uint   = pld92
    sql_attr_uint   = pld93
    sql_attr_uint   = pld94
    sql_attr_uint   = pld95
    sql_attr_uint   = pld96
    sql_attr_uint   = pld97
    sql_attr_uint   = pld98
    sql_attr_uint   = pld99
    sql_attr_uint   = pld100
    sql_attr_uint   = pld101
    sql_attr_uint   = pld102
    sql_attr_uint   = pld103
    sql_attr_uint   = pld104
    sql_attr_uint   = pld105
    sql_attr_uint   = pld106
    sql_attr_uint   = pld107
    sql_attr_uint   = pld108
    sql_attr_uint   = pld109
    sql_attr_uint   = pld110
    sql_attr_uint   = pld111
    sql_attr_uint   = pld112
    sql_attr_uint   = pld113
    sql_attr_uint   = pld114
    sql_attr_uint   = pld115
    sql_attr_uint   = pld116
    sql_attr_uint   = pld117
    sql_attr_uint   = pld118
    sql_attr_uint   = pld119
    sql_attr_uint   = pld120
}
index anifof
{
        source                                  = anifofsrc
        path                                    = /var/data/anifofsrc
        docinfo                                 = extern
        charset_type=utf-8
        charset_table   = 0..9, A..Z->a..z, _-> , a..z
}

Searchd configuration

searchd
{
        port                                    = 3312
        log                                             = /var/log/sphinx/searchd.log
        query_log                               = /var/log/sphinx/query.log
        read_timeout                    = 5
        max_children                    = 30
        pid_file                                = /var/log/searchd.pid
        max_matches                             = 1000000
        seamless_rotate                 = 1
        preopen_indexes                 = 0
        unlink_old                              = 1
}

Indexing gallery data

Now we can index our gallery

/usr/local/bin/indexer --config /usr/local/etc/sphinx.conf --all

Setting up cronjob for index update.

Cronjob command may look like this. We do not use delta indexes. It will be implemented in the future. We just reindex all gallery every hour.

5 * * * * /usr/local/bin/indexer --config /usr/local/etc/sphinx.conf --all --rotate > /dev/null 2>&1

Enabling Sphinx search in gallery

<host> - sphinx service host <port> - sphinx esrvice port <index> - sphinx index name Ex. anifof <max_matches> - number of matches to return. This number should the same as sphinx configuration searchd section. <enabled> - enables sphinx search. Search box etc. appear.<delay_index> - enables or disables delay images indexing, since 771r sphinx indexing relies on new table instead of view, it provides faster indexing, also with help of this feature search by color and keyword at the same time was implemented.

'sphinx' => 
    array (
      'host' => 'localhost',
      'port' => 3312,     
      'index' => 'index_name',
      'enabled' => false,      
      'max_matches' => 1000000, 
      'delay_index' => false     
    ),

Sphinx service control script

This script is not part of the gallery but may be usefull.


#!/bin/sh
# sphinx: Startup script for Sphinx search
#
# chkconfig: 345 86 14
# description:  This is a daemon for high performance full text \
#               search of MySQL and PostgreSQL databases. \
#               See http://www.sphinxsearch.com/ for more info.
#
# processname: searchd
# pidfile: /usr/local/var/log/sphinx/searchd.pid

# Source function library.
. /etc/rc.d/init.d/functions

processname=searchd
servicename=sphinx
RETVAL=0

PATH=$PATH:/usr/local/bin

start() {
    echo -n $"Starting Sphinx daemon: "
    #daemon --check $servicename $processname
    /usr/local/bin/searchd --config /usr/local/etc/sphinx.conf
    RETVAL=$?
    echo
    [ $RETVAL -eq 0 ] && touch /var/lock/subsys/$servicename
}

stop() {
    echo -n $"Stopping Sphinx daemon: "

    killproc -p /var/log/searchd.pid $servicename -TERM
    RETVAL=$?
    echo
    if [ $RETVAL -eq 0 ]; then
        rm -f /var/lock/subsys/$servicename
        rm -f /var/log/searchd.pid
    fi
}

# See how we were called.
case "$1" in
    start)
        start
        ;;
    stop)
        stop
        ;;
    status)
        status $processname
        RETVAL=$?
        ;;
    restart)
        stop
        sleep 3
        start
        ;;
    condrestart)
        if [ -f /var/lock/subsys/$servicename ]; then
            stop
            sleep 3
            start
        fi
        ;;
    *)
        echo $"Usage: $0 {start|stop|status|restart|condrestart}"
        ;;
esac
exit $RETVAL
Back »

Comments: 0

Leave a reply »

 
  • Leave a Reply
    Your gravatar
    Your Name
     
     
     
     
 
About HPPG

High performance photo gallery dedicated for large numbers of image storage.

Get in touch

Donate



Download