]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/SphinxSearch/scripts/gen_config.php
Bringing Sphinx search support up to code: broken out to a plugin, now supports multi...
[quix0rs-gnu-social.git] / plugins / SphinxSearch / scripts / gen_config.php
1 #!/usr/bin/env php
2 <?php
3 /*
4  * StatusNet - the distributed open-source microblogging tool
5  * Copyright (C) 2009, StatusNet, Inc.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU Affero General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.     See the
15  * GNU Affero General Public License for more details.
16  *
17  * You should have received a copy of the GNU Affero General Public License
18  * along with this program.     If not, see <http://www.gnu.org/licenses/>.
19  */
20
21 define('INSTALLDIR', realpath(dirname(__FILE__) . '/../../..'));
22
23 $longoptions = array('base=', 'network');
24
25 $helptext = <<<END_OF_TRIM_HELP
26 Generates sphinx.conf file based on StatusNet configuration.
27     --base               Base dir to Sphinx install
28                          (default /usr/local)
29     --network            Use status_network global config table
30                          (non-functional at present)
31
32
33 END_OF_TRIM_HELP;
34
35 require_once INSTALLDIR . '/scripts/commandline.inc';
36 require dirname(__FILE__) . '/sphinx-utils.php';
37
38
39 $timestamp = date('r');
40 print <<<END
41 #
42 # Sphinx configuration for StatusNet
43 # Generated {$timestamp}
44 #
45
46 END;
47
48 sphinx_iterate_sites('sphinx_site_template');
49
50 print <<<END
51
52 indexer
53 {
54     mem_limit               = 300M
55 }
56
57 searchd
58 {
59     port                    = 3312
60     log                     = {$base}/log/searchd.log
61     query_log               = {$base}/log/query.log
62     read_timeout            = 5
63     max_children            = 30
64     pid_file                = {$base}/log/searchd.pid
65     max_matches             = 1000
66     seamless_rotate         = 1
67     preopen_indexes         = 0
68     unlink_old              = 1
69 }
70
71 END;
72
73
74
75 /**
76  * Build config entries for a single site
77  * @fixme we only seem to have master DB currently available...
78  */
79 function sphinx_site_template($sn)
80 {
81     return
82         sphinx_template($sn,
83             'profile',
84             'SELECT id, UNIX_TIMESTAMP(created) as created_ts, nickname, fullname, location, bio, homepage FROM profile',
85             'SELECT * FROM profile where id = $id') .
86         sphinx_template($sn,
87             'notice',
88             'SELECT id, UNIX_TIMESTAMP(created) as created_ts, content FROM notice',
89             'SELECT * FROM notice where notice.id = $id AND notice.is_local != -2');
90 }
91
92 function sphinx_template($sn, $table, $query, $query_info)
93 {
94     $base = sphinx_base();
95     $dbtype = common_config('db', 'type');
96
97     print <<<END
98
99 #
100 # {$sn->sitename}
101 #
102 source {$sn->dbname}_src_{$table}
103 {
104     type                    = {$dbtype}
105     sql_host                = {$sn->dbhost}
106     sql_user                = {$sn->dbuser}
107     sql_pass                = {$sn->dbpass}
108     sql_db                  = {$sn->dbname}
109     sql_query_pre           = SET NAMES utf8;
110     sql_query               = {$query}
111     sql_query_info          = {$query_info}
112     sql_attr_timestamp      = created_ts
113 }
114
115 index {$sn->dbname}_{$table}
116 {
117     source                  = {$sn->dbname}_src_{$table}
118     path                    = {$base}/data/{$sn->dbname}_{$table}
119     docinfo                 = extern
120     charset_type            = utf-8
121     min_word_len            = 3
122 }
123
124
125 END;
126 }