Make search mechanism pluggable
Currently, TinyTinyRSS can use raw SQL or the Sphinx search engine for searching. It would be nice if other search engines (such as Xapian) could be used, or if features of the underlying SQL engine (such as MySQL's FULLTEXT indexes) could be leveraged. This commit makes searching into a plugin hook, falling back to the builtin behavior if no search plugin is active. The Sphinx search behavior has been broken out into a plugin.master
parent
87ddd5e1f9
commit
baaf4c3043
@ -1,3 +1,3 @@
|
|||||||
<?php # This file has been generated at: Fri Sep 27 13:42:37 MSK 2013
|
<?php # This file has been generated at: Fri Sep 27 13:42:37 MSK 2013
|
||||||
define('GENERATED_CONFIG_CHECK', 26);
|
define('GENERATED_CONFIG_CHECK', 26);
|
||||||
$requred_defines = array( 'DB_TYPE', 'DB_HOST', 'DB_USER', 'DB_NAME', 'DB_PASS', 'MYSQL_CHARSET', 'SELF_URL_PATH', 'FEED_CRYPT_KEY', 'SINGLE_USER_MODE', 'SIMPLE_UPDATE_MODE', 'PHP_EXECUTABLE', 'LOCK_DIRECTORY', 'CACHE_DIR', 'ICONS_DIR', 'ICONS_URL', 'AUTH_AUTO_CREATE', 'AUTH_AUTO_LOGIN', 'FORCE_ARTICLE_PURGE', 'PUBSUBHUBBUB_HUB', 'PUBSUBHUBBUB_ENABLED', 'SPHINX_ENABLED', 'SPHINX_SERVER', 'SPHINX_INDEX', 'ENABLE_REGISTRATION', 'REG_NOTIFY_ADDRESS', 'REG_MAX_USERS', 'SESSION_COOKIE_LIFETIME', 'SESSION_CHECK_ADDRESS', 'SMTP_FROM_NAME', 'SMTP_FROM_ADDRESS', 'DIGEST_SUBJECT', 'SMTP_SERVER', 'SMTP_LOGIN', 'SMTP_PASSWORD', 'SMTP_SECURE', 'CHECK_FOR_NEW_VERSION', 'DETECT_ARTICLE_LANGUAGE', 'ENABLE_GZIP_OUTPUT', 'PLUGINS', 'LOG_DESTINATION', 'CONFIG_VERSION'); ?>
|
$requred_defines = array( 'DB_TYPE', 'DB_HOST', 'DB_USER', 'DB_NAME', 'DB_PASS', 'MYSQL_CHARSET', 'SELF_URL_PATH', 'FEED_CRYPT_KEY', 'SINGLE_USER_MODE', 'SIMPLE_UPDATE_MODE', 'PHP_EXECUTABLE', 'LOCK_DIRECTORY', 'CACHE_DIR', 'ICONS_DIR', 'ICONS_URL', 'AUTH_AUTO_CREATE', 'AUTH_AUTO_LOGIN', 'FORCE_ARTICLE_PURGE', 'PUBSUBHUBBUB_HUB', 'PUBSUBHUBBUB_ENABLED', 'ENABLE_REGISTRATION', 'REG_NOTIFY_ADDRESS', 'REG_MAX_USERS', 'SESSION_COOKIE_LIFETIME', 'SESSION_CHECK_ADDRESS', 'SMTP_FROM_NAME', 'SMTP_FROM_ADDRESS', 'DIGEST_SUBJECT', 'SMTP_SERVER', 'SMTP_LOGIN', 'SMTP_PASSWORD', 'SMTP_SECURE', 'CHECK_FOR_NEW_VERSION', 'DETECT_ARTICLE_LANGUAGE', 'ENABLE_GZIP_OUTPUT', 'PLUGINS', 'LOG_DESTINATION', 'CONFIG_VERSION'); ?>
|
||||||
|
@ -0,0 +1,60 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class Search_Sphinx extends Plugin {
|
||||||
|
function about() {
|
||||||
|
return array(1.0,
|
||||||
|
"Delegate searching for articles to Sphinx",
|
||||||
|
"hoelzro",
|
||||||
|
true);
|
||||||
|
}
|
||||||
|
|
||||||
|
function init($host) {
|
||||||
|
$host->add_hook($host::HOOK_SEARCH, $this);
|
||||||
|
|
||||||
|
require_once __DIR__ . "/sphinxapi.php";
|
||||||
|
}
|
||||||
|
|
||||||
|
function hook_search($search) {
|
||||||
|
$offset = 0;
|
||||||
|
$limit = 500;
|
||||||
|
|
||||||
|
$sphinxClient = new SphinxClient();
|
||||||
|
|
||||||
|
$sphinxpair = explode(":", SPHINX_SERVER, 2);
|
||||||
|
|
||||||
|
$sphinxClient->SetServer($sphinxpair[0], (int)$sphinxpair[1]);
|
||||||
|
$sphinxClient->SetConnectTimeout(1);
|
||||||
|
|
||||||
|
$sphinxClient->SetFieldWeights(array('title' => 70, 'content' => 30,
|
||||||
|
'feed_title' => 20));
|
||||||
|
|
||||||
|
$sphinxClient->SetMatchMode(SPH_MATCH_EXTENDED2);
|
||||||
|
$sphinxClient->SetRankingMode(SPH_RANK_PROXIMITY_BM25);
|
||||||
|
$sphinxClient->SetLimits($offset, $limit, 1000);
|
||||||
|
$sphinxClient->SetArrayResult(false);
|
||||||
|
$sphinxClient->SetFilter('owner_uid', array($_SESSION['uid']));
|
||||||
|
|
||||||
|
$result = $sphinxClient->Query($search, SPHINX_INDEX);
|
||||||
|
|
||||||
|
$ids = array();
|
||||||
|
|
||||||
|
if (is_array($result['matches'])) {
|
||||||
|
foreach (array_keys($result['matches']) as $int_id) {
|
||||||
|
$ref_id = $result['matches'][$int_id]['attrs']['ref_id'];
|
||||||
|
array_push($ids, $ref_id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$ids = join(",", $ids);
|
||||||
|
|
||||||
|
if ($ids)
|
||||||
|
return array("ref_id IN ($ids)", array());
|
||||||
|
else
|
||||||
|
return array("ref_id = -1", array());
|
||||||
|
}
|
||||||
|
|
||||||
|
function api_version() {
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
Loading…
Reference in New Issue