summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorRob Hoelz <[email protected]>2014-04-14 23:18:33 -0500
committerAndrew Dolgov <[email protected]>2014-04-23 04:49:54 +0000
commitbaaf4c3043f428ec009dd48b85e1c2d6cb8abee4 (patch)
tree7bdf437023fad735a58d149c4177b70b20630b97 /include
parent87ddd5e1f9465a24fdb087356e31ab8fe73bdf0a (diff)
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.
Diffstat (limited to 'include')
-rw-r--r--include/functions2.php50
-rw-r--r--include/sanity_check.php5
-rw-r--r--include/sanity_config.php2
3 files changed, 7 insertions, 50 deletions
diff --git a/include/functions2.php b/include/functions2.php
index ca58ea6c5..22c602362 100644
--- a/include/functions2.php
+++ b/include/functions2.php
@@ -397,20 +397,15 @@
$search_words = array();
if ($search) {
+ foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_SEARCH) as $plugin) {
+ list($search_query_part, $search_words) = $plugin->hook_search($search);
+ }
- if (SPHINX_ENABLED) {
- $ids = join(",", @sphinx_search($search, 0, 500));
-
- if ($ids)
- $search_query_part = "ref_id IN ($ids) AND ";
- else
- $search_query_part = "ref_id = -1 AND ";
-
- } else {
+ // fall back in case of no plugins
+ if (!$search_query_part) {
list($search_query_part, $search_words) = search_to_sql($search);
- $search_query_part .= " AND ";
}
-
+ $search_query_part .= " AND ";
} else {
$search_query_part = "";
}
@@ -1994,39 +1989,6 @@
}
}
- function sphinx_search($query, $offset = 0, $limit = 30) {
- require_once 'lib/sphinxapi.php';
-
- $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($query, 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);
- }
- }
-
- return $ids;
- }
-
function cleanup_tags($days = 14, $limit = 1000) {
if (DB_TYPE == "pgsql") {
diff --git a/include/sanity_check.php b/include/sanity_check.php
index 1aa581bfc..6bec43051 100644
--- a/include/sanity_check.php
+++ b/include/sanity_check.php
@@ -146,11 +146,6 @@
array_push($errors, "PHP support for CURL is required for PubSubHubbub.");
}
- if (SPHINX_ENABLED && class_exists("SphinxClient")) {
- array_push($errors, "Your PHP has a separate systemwide Sphinx client installed which conflicts with the client library used by tt-rss. Either remove the system library or disable Sphinx support.");
-
- }
-
if (!class_exists("DOMDocument")) {
array_push($errors, "PHP support for DOMDocument is required, but was not found.");
}
diff --git a/include/sanity_config.php b/include/sanity_config.php
index 99e83e0d9..76fba4b81 100644
--- a/include/sanity_config.php
+++ b/include/sanity_config.php
@@ -1,3 +1,3 @@
<?php # This file has been generated at: Fri Sep 27 13:42:37 MSK 2013
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'); ?>