sphinx search for notices
darcs-hash:20081120215041-099f7-db396a60755d551099122b58634b7550d5606d88.gz
This commit is contained in:
parent
aeaf70a472
commit
bf72cde96f
@ -41,15 +41,11 @@ class NoticesearchAction extends SearchAction {
|
|||||||
# lcase it for comparison
|
# lcase it for comparison
|
||||||
$q = strtolower($q);
|
$q = strtolower($q);
|
||||||
|
|
||||||
if(common_config('db','type')=='mysql') {
|
$search_engine = $notice->getSearchEngine('identica_notices');
|
||||||
$notice->whereAdd('MATCH(content) against (\''.addslashes($q).'\')');
|
$search_engine->query($q);
|
||||||
} else {
|
|
||||||
$notice->whereAdd('to_tsvector(\'english\', content) @@ plainto_tsquery(\''.addslashes($q).'\')');
|
|
||||||
}
|
|
||||||
|
|
||||||
# Ask for an extra to see if there's more.
|
# Ask for an extra to see if there's more.
|
||||||
|
$search_engine->limit((($page-1)*NOTICES_PER_PAGE), NOTICES_PER_PAGE + 1);
|
||||||
$notice->limit((($page-1)*NOTICES_PER_PAGE), NOTICES_PER_PAGE + 1);
|
|
||||||
|
|
||||||
$cnt = $notice->find();
|
$cnt = $notice->find();
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ class PeoplesearchAction extends SearchAction {
|
|||||||
# lcase it for comparison
|
# lcase it for comparison
|
||||||
$q = strtolower($q);
|
$q = strtolower($q);
|
||||||
|
|
||||||
$search_engine = $profile->getSearchEngine();
|
$search_engine = $profile->getSearchEngine('identica_people');
|
||||||
|
|
||||||
$search_engine->query($q);
|
$search_engine->query($q);
|
||||||
|
|
||||||
|
@ -169,4 +169,19 @@ class Memcached_DataObject extends DB_DataObject
|
|||||||
return $c->get(Memcached_DataObject::cacheKey($cls, $pkeys, $pvals));
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -46,21 +46,6 @@ class Profile extends Memcached_DataObject
|
|||||||
/* the code above is auto generated do not remove the tag below */
|
/* the code above is auto generated do not remove the tag below */
|
||||||
###END_AUTOCODE
|
###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) {
|
function getAvatar($width, $height=NULL) {
|
||||||
if (is_null($height)) {
|
if (is_null($height)) {
|
||||||
$height = $width;
|
$height = $width;
|
||||||
|
@ -21,9 +21,11 @@ if (!defined('LACONICA')) { exit(1); }
|
|||||||
|
|
||||||
class SearchEngine {
|
class SearchEngine {
|
||||||
protected $profile;
|
protected $profile;
|
||||||
|
protected $table;
|
||||||
|
|
||||||
function __construct($profile) {
|
function __construct($profile, $table) {
|
||||||
$this->profile = $profile;
|
$this->profile = $profile;
|
||||||
|
$this->table = $table;
|
||||||
}
|
}
|
||||||
|
|
||||||
function query($q) {
|
function query($q) {
|
||||||
@ -37,8 +39,8 @@ class SearchEngine {
|
|||||||
class SphinxSearch extends SearchEngine {
|
class SphinxSearch extends SearchEngine {
|
||||||
private $sphinx;
|
private $sphinx;
|
||||||
|
|
||||||
function __construct($profile) {
|
function __construct($profile, $table) {
|
||||||
parent::__construct($profile);
|
parent::__construct($profile, $table);
|
||||||
$this->sphinx = new SphinxClient;
|
$this->sphinx = new SphinxClient;
|
||||||
$this->sphinx->setServer(common_config('sphinx', 'server'), common_config('sphinx', 'port'));
|
$this->sphinx->setServer(common_config('sphinx', 'server'), common_config('sphinx', 'port'));
|
||||||
}
|
}
|
||||||
@ -49,7 +51,7 @@ class SphinxSearch extends SearchEngine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function query($q) {
|
function query($q) {
|
||||||
$result = $this->sphinx->query($q);
|
$result = $this->sphinx->query($q, $this->table);
|
||||||
if (!isset($result['matches'])) return false;
|
if (!isset($result['matches'])) return false;
|
||||||
$id_set = join(', ', array_keys($result['matches']));
|
$id_set = join(', ', array_keys($result['matches']));
|
||||||
return $this->profile->whereAdd("id in ($id_set)");
|
return $this->profile->whereAdd("id in ($id_set)");
|
||||||
|
Loading…
Reference in New Issue
Block a user