# MySQL apt-get /etc/apt/sources.list deb http://repo.mysql.com/apt/debian/ wheezy mysql-5.6 deb-src http://repo.mysql.com/apt/debian/ wheezy mysql-5.6 # MySQL apt-get install mysql-client unixodbc libpq5 libmysqlclient18 # Sphinx ( 2.2.9) wget http://sphinxsearch.com/files/sphinxsearch_2.2.9-release-1~wheezy_amd64.deb # dpkg -i sphinxsearch_2.2.9-release-1~wheezy_amd64.deb
/etc/init.d/sphinxsearch stop
). Next you need to create a directory structure for storing indexes, in our case there will be two - the main and delta index. The main stores all data, delta only for today to speed up indexing. mkdir /opt/sphinx mkdir /opt/sphinx/data # mkdir /opt/sphinx/data/review # mkdir /opt/sphinx/data/review_delta # mkdir /opt/sphinx/log/
# , ( PostgreSQL) source base { type = pgsql sql_host = 162.198.0.3 sql_user = postgres_login sql_pass = postgres_password sql_db = cackle sql_port = 5179 } # index base { # charset_type = utf-8 # morphology = stem_enru # 2 min_word_len = 2 } # review source review : base { # search_fulltext # id review ( id search_fulltext ) sql_query_pre = DELETE FROM search_fulltext WHERE type = 'review' sql_query_pre = INSERT INTO search_fulltext SELECT 'review', MAX(id) FROM review # id, site_id, status, pros, cons, comment review sql_query = SELECT id, site_id, status, pros, cons, comment FROM review # sql_attr_uint = site_id # (, , , ) sql_attr_uint = status } # review review # /opt/sphinx/data/review index review : base { source = review path = /opt/sphinx/data/review } # review source review_delta : review { # , sql_query_pre review # - SQL (SELECT 1) sql_query_pre = SELECT 1 # , id, id search_fulltext sql_query = SELECT id, site_id, status, pros, cons, comment FROM review WHERE id > (SELECT id FROM search_fulltext WHERE type = 'review') } # index review_delta : review { source = review_delta path = /opt/sphinx/data/review_delta } # searchd # mysql (mysql_version_string = 5.5.21) searchd { listen = localhost:9306:mysql41 mysql_version_string = 5.5.21 log = /opt/sphinx/log/searchd.log query_log = /opt/sphinx/log/query.log pid_file = /opt/sphinx/log/searchd.pid }
indexer --config /etc/sphinxsearch/sphinx.conf review
# id 1 '', id, 0 15 SELECT id FROM review WHERE site_id = 1 AND MATCH('') ORDER BY id DESC LIMIT 0,15 # id 1, 2, 738, 35302 1 (), 3 () SELECT id FROM review WHERE site in (1, 2, 738, 35302) AND status in (1, 3) AND MATCH(' ') ORDER BY id DESC LIMIT 0, 15
crontab -e # 5 review_delta ( id id search_fulltext) */5 * * * * indexer --rotate --quiet --config /etc/sphinxsearch/sphinx.conf review_delta # ( ) review_update.sh 0 1 * * * /opt/sphinx/review_update.sh
PGPASSWORD=postgres_password; export PGPASSWORD; indexer --rotate --quiet --config /etc/sphinxsearch/sphinx.conf review_delta; psql --host 162.198.0.3 --port 5179 --username "postgres_login" -c "UPDATE search_fulltext SET id = (SELECT MAX(id) FROM review) WHERE type = 'review'" "cackle"; indexer --merge review review_delta --rotate --quiet --config /etc/sphinxsearch/sphinx.conf;
# id 1 '', id, 0 15 SELECT id FROM review, review_delta WHERE site_id = 1 AND MATCH('') ORDER BY id DESC LIMIT 0,15 # id 1, 2, 738, 35302 1 (), 3 () SELECT id FROM review, review_delta WHERE site in (1, 2, 738, 35302) AND status in (1, 3) AND MATCH(' ') ORDER BY id DESC LIMIT 0, 15
Source: https://habr.com/ru/post/261829/
All Articles