Created
June 14, 2012 10:00
-
-
Save anonymous/2929397 to your computer and use it in GitHub Desktop.
generate.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import config | |
CONST_SQL_QUERY = """ \\ | |
SELECT t_fast.topic_id, t_fast.topic_title, UNIX_TIMESTAMP(t_fast.topic_date_add) as topic_date_add, \\ | |
tc.topic_text, t_fast.topic_publish \\ | |
FROM {prefix}topic as t_fast, {prefix}topic_content AS tc \\ | |
WHERE t_fast.topic_id=tc.topic_id AND t_fast.topic_id>=$start AND t_fast.topic_id<=$end | |
""" | |
CONST_SQL_QUERY2 = """\\ | |
SELECT comment_id, comment_text, UNIX_TIMESTAMP(comment_date) as comment_date, comment_delete \\ | |
FROM {prefix}comment \\ | |
WHERE target_type='topic' AND comment_id>=$start AND comment_id<=$end | |
""" | |
with open("sphinx.conf", "w") as f: | |
for site in config.sites: | |
# generate source | |
f.write("source %sSource\n{\ntype=mysql\nsql_host=localhost\nsql_user=%s\nsql_pass=%s\nsql_db=%s\nsql_port=3306\nsql_sock=/var/run/mysqld/mysqld.sock\nmysql_connect_flags=32\nsql_query_pre=SET NAMES utf8\nsql_query_pre=SET SESSION query_cache_type=OFF\n}\n" % (site['db'], site['user'], site['password'], site['db'])) | |
f.write("source %sTopics : %sSource\n{\nsql_query=" % (site['db'], site['db']) +CONST_SQL_QUERY.replace('{prefix}', site['prefix'])+"\nsql_query_range=SELECT MIN(topic_id),MAX(topic_id) FROM %stopic\nsql_range_step=1000\nsql_attr_uint=topic_publish\nsql_attr_timestamp=topic_data_add\nsql_attr_multi=uint tag from query; SELECT topic_id, topic_tag_id FROM %stopic_tag\nsql_ranged_throttle=0\n}\n" % (site['prefix'], site['prefix'])) | |
f.write("source %sComments : %sSource\n{\nsql_query=" % (site['db'], site['db']) +CONST_SQL_QUERY2.replace('{prefix}', site['prefix'])+"\nsql_query_range=SELECT MIN(comment_id),MAX(comment_id) FROM %scomment\nsql_range_step=5000\nsql_attr_uint=comment_delete\nsql_attr_timestamp=comment_date\n}\n" % (site['prefix'])) | |
f.write("index %stopicsIndex\n{\nsource=%sTopics\npath=/var/lib/data/%sTopics\ndocinfo=extern\nmlock=0\nmorphology=stem_enru\ncharset_type=utf-8\nhtml_strip=1\nhtml_remove_elements=style,script,code\n}\n" % (site['db'], site['db'], site['db'])) | |
f.write("index %scommentsIndex\n{\nsource=%sComments\npath=/var/lib/data/%sComments\ndocinfo=extern\nmlock=0\nmorphology=stem_enru\ncharset_type=utf-8\nhtml_strip=1\nhtml_remove_elements=style,script,code\n}\n\n" % (site['db'], site['db'], site['db'])) | |
# time to write global config | |
f.write("indexer\n{\nmem_limit=32M\n}") | |
f.write("searchd\n{\nlisten=127.0.0.1:3312\nlog=/var/log/sphinx/searchd.log\nquery_log=/var/log/sphinx/query.log\nread_timeout=5\nmax_children=30\npid_file=/var/log/sphinx/searchd.pid\n}"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment