3 * StatusNet, the distributed open-source microblogging tool
7 * LICENCE: 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.
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.
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/>.
22 * @author Brion Vibber <brion@status.net>
23 * @copyright 2009 Control Yourself, Inc.
24 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
25 * @link http://laconi.ca/
28 if (!defined('STATUSNET')) {
32 // Set defaults if not already set in the config array...
35 array('enabled' => true,
36 'server' => 'localhost',
38 foreach($sphinxDefaults as $key => $val) {
39 if (!isset($config['sphinx'][$key])) {
40 $config['sphinx'][$key] = $val;
47 * Plugin for Sphinx search backend.
51 * @author Brion Vibber <brion@status.net>
52 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
53 * @link http://laconi.ca/
54 * @link http://twitter.com/
57 class SphinxSearchPlugin extends Plugin
60 * Automatically load any classes used
62 * @param string $cls the class
63 * @return boolean hook return
65 function onAutoload($cls)
69 include_once INSTALLDIR . '/plugins/SphinxSearch/' .
70 strtolower($cls) . '.php';
78 * Create sphinx search engine object for the given table type.
80 * @param Memcached_DataObject $target
81 * @param string $table
82 * @param out &$search_engine SearchEngine object on output if successful
83 * @ return boolean hook return
85 function onGetSearchEngine(Memcached_DataObject $target, $table, &$search_engine)
87 if (common_config('sphinx', 'enabled')) {
88 if (!class_exists('SphinxClient')) {
89 throw new ServerException('Sphinx PHP extension must be installed.');
91 $engine = new SphinxSearch($target, $table);
92 if ($engine->is_connected()) {
93 $search_engine = $engine;
97 // Sphinx disabled or disconnected