source src_mysql { type = mysql sql_host = localhost sql_user = sphinx sql_pass = secret sql_range_step = 1000 } source src_news : src_mysql { sql_db = project sql_query_pre = SET NAMES utf8 sql_query_pre = SET CHARACTER SET utf8 sql_query_pre = REPLACE INTO sph_counter SELECT 'src_news', MAX(id) FROM news sql_query_range = SELECT MIN(id), MAX(id) FROM news sql_query = SELECT id as news_id, title, content FROM news WHERE id>=$start AND id<=$end } source src_news_delta : src_news { sql_query_pre = SET NAMES utf8 sql_query_pre = SET CHARACTER SET utf8 sql_query_range = sql_query = SELECT id as news_id title, content FROM news \ WHERE id > ( SELECT max_value FROM sph_counter WHERE source = 'src_news') sql_query_post = REPLACE INTO sph_counter SELECT 'src_news', MAX(id) FROM news }
CREATE TABLE IF NOT EXISTS `sph_counter` ( `source` varchar(100) NOT NULL DEFAULT '', `max_value` bigint(20) NOT NULL, `hostname` varchar(50) NOT NULL DEFAULT '', PRIMARY KEY (`source`,`hostname`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
source src_news : src_mysql { sql_db = project sql_query_pre = SET NAMES utf8 sql_query_pre = SET CHARACTER SET utf8 sql_query_pre = REPLACE INTO sph_counter SELECT 'src_news', MAX(id), @@hostname FROM news sql_query_range = SELECT MIN(id), MAX(id) FROM news sql_query = SELECT id as news_id, title, content FROM news WHERE id>=$start AND id<=$end } source src_news_delta : src_news { sql_query_pre = SET NAMES utf8 sql_query_pre = SET CHARACTER SET utf8 sql_query_range = sql_query = SELECT id as news_id, title, content FROM news \ WHERE id > ( SELECT max_value FROM sph_counter WHERE source = 'src_news' AND hostname = @@hostname) sql_query_post = REPLACE INTO sph_counter SELECT 'src_news', MAX(id), @@hostname FROM news }
source src_news : src_mysql { sql_db = project sql_query_pre = SET NAMES utf8 sql_query_pre = SET CHARACTER SET utf8 sql_query_pre = SELECT @sphinx_instance:=IF(STRCMP(@sphinx_host:=SUBSTRING_INDEX(host,':',1),'localhost'),@sphinx_host,@@hostname) AS sphinx_instance \ FROM information_schema.processlist WHERE ID=connection_id(); sql_query_pre = REPLACE INTO sph_counter SELECT 'src_news', MAX(id), @sphinx_instance FROM news sql_query_range = SELECT MIN(id), MAX(id) FROM news sql_query = SELECT id as news_id, title, content FROM news WHERE id>=$start AND id<=$end } source src_news_delta : src_news { sql_query_pre = SET NAMES utf8 sql_query_pre = SET CHARACTER SET utf8 sql_query_pre = SELECT @sphinx_instance:=IF(STRCMP(@sphinx_host:=SUBSTRING_INDEX(host,':',1),'localhost'),@sphinx_host,@@hostname) AS sphinx_instance \ FROM information_schema.processlist WHERE ID=connection_id(); sql_query_pre = REPLACE INTO sph_counter SELECT 'src_news', MAX(id), @sphinx_instance FROM news sql_query_range = sql_query = SELECT id as news_id, title, content FROM news \ WHERE id > ( SELECT max_value FROM sph_counter WHERE source = 'src_news' AND hostname = @sphinx_instance) sql_query_post = REPLACE INTO sph_counter SELECT 'src_news', MAX(id), @sphinx_instance FROM news }
Source: https://habr.com/ru/post/146999/
All Articles