Guest User

Untitled

a guest
Oct 20th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.61 KB | None | 0 0
  1. #!/usr/bin/env python
  2. import config
  3.  
  4. CONST_SQL_QUERY = """ \\
  5. SELECT t_fast.topic_id, t_fast.topic_title, UNIX_TIMESTAMP(t_fast.topic_date_add) as topic_date_add, \\
  6. tc.topic_text, t_fast.topic_publish \\
  7. FROM {prefix}topic as t_fast, {prefix}topic_content AS tc \\
  8. WHERE t_fast.topic_id=tc.topic_id AND t_fast.topic_id>=$start AND t_fast.topic_id<=$end
  9. """
  10. CONST_SQL_QUERY2 = """\\
  11. SELECT comment_id, comment_text, UNIX_TIMESTAMP(comment_date) as comment_date, comment_delete \\
  12. FROM {prefix}comment \\
  13. WHERE target_type='topic' AND comment_id>=$start AND comment_id<=$end
  14.  
  15. """
  16.  
  17. with open("sphinx.conf", "w") as f:
  18. for site in config.sites:
  19. # generate source
  20. 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']))
  21. 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']))
  22. 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']))
  23. 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']))
  24. 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']))
  25.  
  26. # time to write global config
  27. f.write("indexer\n{\nmem_limit=32M\n}")
  28. 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}");
Add Comment
Please, Sign In to add comment