add support for Sphinx search engine

This commit is contained in:
Andrew Dolgov 2010-11-12 21:44:19 +03:00
parent 353221477b
commit e4f7f8dff2
5 changed files with 1692 additions and 13 deletions

View File

@ -164,7 +164,14 @@
// intervals is disabled and all articles (which are not starred) // intervals is disabled and all articles (which are not starred)
// older than this amount of days are purged. // older than this amount of days are purged.
define('CONFIG_VERSION', 19); define('SPHINX_ENABLE', false);
// Enable fulltext search using Sphinx (http://www.sphinxsearch.com)
// Please see http://tt-rss.org/wiki/SphinxSearch for more information.
define('SPHINX_INDEX', 'ttrss');
// Index name in Sphinx configuration
define('CONFIG_VERSION', 20);
// Expected config version. Please update this option in config.php // Expected config version. Please update this option in config.php
// if necessary (after migrating all new options from this file). // if necessary (after migrating all new options from this file).

View File

@ -106,6 +106,7 @@
require_once 'version.php'; require_once 'version.php';
require_once 'lib/phpmailer/class.phpmailer.php'; require_once 'lib/phpmailer/class.phpmailer.php';
require_once 'lib/sphinxapi.php';
define('MAGPIE_USER_AGENT_EXT', ' (Tiny Tiny RSS/' . VERSION . ')'); define('MAGPIE_USER_AGENT_EXT', ' (Tiny Tiny RSS/' . VERSION . ')');
define('MAGPIE_OUTPUT_ENCODING', 'UTF-8'); define('MAGPIE_OUTPUT_ENCODING', 'UTF-8');
@ -3290,8 +3291,18 @@
if ($search) { if ($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 {
$search_query_part = getSearchSql($search, $match_on); $search_query_part = getSearchSql($search, $match_on);
$search_query_part .= " AND "; $search_query_part .= " AND ";
}
} else { } else {
$search_query_part = ""; $search_query_part = "";
@ -7123,4 +7134,33 @@
} }
} }
function sphinx_search($query, $offset = 0, $limit = 30) {
$sphinxClient = new SphinxClient();
$sphinxClient->SetServer('localhost', 9312);
$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;
}
?> ?>

1626
lib/sphinxapi.php Normal file

File diff suppressed because it is too large Load Diff

View File

@ -374,6 +374,8 @@
print "<div class=\"dlgSecCont\">"; print "<div class=\"dlgSecCont\">";
if (!SPHINX_ENABLE) {
print "<input onkeypress=\"return filterCR(event, search)\" print "<input onkeypress=\"return filterCR(event, search)\"
name=\"query\" size=\"20\" type=\"search\" value=''>"; name=\"query\" size=\"20\" type=\"search\" value=''>";
@ -385,6 +387,10 @@
"both" => __("Title or content")); "both" => __("Title or content"));
print_select_hash("match_on", 3, $search_fields); print_select_hash("match_on", 3, $search_fields);
} else {
print "<input onkeypress=\"return filterCR(event, search)\"
name=\"query\" size=\"50\" type=\"search\" value=''>";
}
print "<br/>".__('Limit search to:')." "; print "<br/>".__('Limit search to:')." ";

View File

@ -1,7 +1,7 @@
<?php <?php
require_once "functions.php"; require_once "functions.php";
define('EXPECTED_CONFIG_VERSION', 19); define('EXPECTED_CONFIG_VERSION', 20);
define('SCHEMA_VERSION', 74); define('SCHEMA_VERSION', 74);
if (!file_exists("config.php")) { if (!file_exists("config.php")) {