From bf72cde96f6c60b4b7dbca6c5d011f31bcc186f7 Mon Sep 17 00:00:00 2001 From: millette Date: Thu, 20 Nov 2008 16:50:41 -0500 Subject: [PATCH] sphinx search for notices darcs-hash:20081120215041-099f7-db396a60755d551099122b58634b7550d5606d88.gz --- actions/noticesearch.php | 10 +++------- actions/peoplesearch.php | 2 +- classes/Memcached_DataObject.php | 15 +++++++++++++++ classes/Profile.php | 15 --------------- classes/SearchEngines.php | 10 ++++++---- 5 files changed, 25 insertions(+), 27 deletions(-) diff --git a/actions/noticesearch.php b/actions/noticesearch.php index bc052d512f..f8dad2a20e 100644 --- a/actions/noticesearch.php +++ b/actions/noticesearch.php @@ -41,15 +41,11 @@ class NoticesearchAction extends SearchAction { # lcase it for comparison $q = strtolower($q); - if(common_config('db','type')=='mysql') { - $notice->whereAdd('MATCH(content) against (\''.addslashes($q).'\')'); - } else { - $notice->whereAdd('to_tsvector(\'english\', content) @@ plainto_tsquery(\''.addslashes($q).'\')'); - } + $search_engine = $notice->getSearchEngine('identica_notices'); + $search_engine->query($q); # Ask for an extra to see if there's more. - - $notice->limit((($page-1)*NOTICES_PER_PAGE), NOTICES_PER_PAGE + 1); + $search_engine->limit((($page-1)*NOTICES_PER_PAGE), NOTICES_PER_PAGE + 1); $cnt = $notice->find(); diff --git a/actions/peoplesearch.php b/actions/peoplesearch.php index d493c76678..fa54dc9f7c 100644 --- a/actions/peoplesearch.php +++ b/actions/peoplesearch.php @@ -40,7 +40,7 @@ class PeoplesearchAction extends SearchAction { # lcase it for comparison $q = strtolower($q); - $search_engine = $profile->getSearchEngine(); + $search_engine = $profile->getSearchEngine('identica_people'); $search_engine->query($q); diff --git a/classes/Memcached_DataObject.php b/classes/Memcached_DataObject.php index f8e1b9accc..e1d58dd70e 100644 --- a/classes/Memcached_DataObject.php +++ b/classes/Memcached_DataObject.php @@ -169,4 +169,19 @@ class Memcached_DataObject extends DB_DataObject return $c->get(Memcached_DataObject::cacheKey($cls, $pkeys, $pvals)); } } + + function getSearchEngine($table) { + require_once INSTALLDIR.'/classes/SearchEngines.php'; + static $search_engine; + if (!isset($search_engine)) { + if (common_config('sphinx', 'enabled')) { + $search_engine = new SphinxSearch($this, $table); + } elseif ('mysql' === common_config('db', 'type')) { + $search_engine = new MySQLSearch($this, $table); + } else { + $search_engine = new PGSearch($this, $table); + } + } + return $search_engine; + } } diff --git a/classes/Profile.php b/classes/Profile.php index 9de92ec4bc..794dc1de93 100644 --- a/classes/Profile.php +++ b/classes/Profile.php @@ -46,21 +46,6 @@ class Profile extends Memcached_DataObject /* the code above is auto generated do not remove the tag below */ ###END_AUTOCODE - function getSearchEngine() { - require_once INSTALLDIR.'/classes/SearchEngines.php'; - static $search_engine; - if (!isset($search_engine)) { - if (common_config('sphinx', 'enabled')) { - $search_engine = new SphinxSearch($this); - } elseif ('mysql' === common_config('db', 'type')) { - $search_engine = new MySQLSearch($this); - } else { - $search_engine = new PGSearch($this); - } - } - return $search_engine; - } - function getAvatar($width, $height=NULL) { if (is_null($height)) { $height = $width; diff --git a/classes/SearchEngines.php b/classes/SearchEngines.php index e5f4e14ea7..253e0028be 100644 --- a/classes/SearchEngines.php +++ b/classes/SearchEngines.php @@ -21,9 +21,11 @@ if (!defined('LACONICA')) { exit(1); } class SearchEngine { protected $profile; + protected $table; - function __construct($profile) { + function __construct($profile, $table) { $this->profile = $profile; + $this->table = $table; } function query($q) { @@ -37,8 +39,8 @@ class SearchEngine { class SphinxSearch extends SearchEngine { private $sphinx; - function __construct($profile) { - parent::__construct($profile); + function __construct($profile, $table) { + parent::__construct($profile, $table); $this->sphinx = new SphinxClient; $this->sphinx->setServer(common_config('sphinx', 'server'), common_config('sphinx', 'port')); } @@ -49,7 +51,7 @@ class SphinxSearch extends SearchEngine { } function query($q) { - $result = $this->sphinx->query($q); + $result = $this->sphinx->query($q, $this->table); if (!isset($result['matches'])) return false; $id_set = join(', ', array_keys($result['matches'])); return $this->profile->whereAdd("id in ($id_set)");