Add like for search

This commit is contained in:
Evan Prodromou 2009-06-21 21:50:35 -07:00
parent 02a4ca9e2e
commit 876ab05927
4 changed files with 45 additions and 3 deletions

13
README
View File

@ -1247,7 +1247,6 @@ Options for group functionality.
maxaliases: maximum number of aliases a group can have. Default 3. Set
to 0 or less to prevent aliases in a group.
oohembed
--------
@ -1255,6 +1254,18 @@ oEmbed endpoint for multimedia attachments (links in posts).
endpoint: oohembed endpoint using http://oohembed.com/ software.
search
------
Some stuff for search.
type: type of search. Ignored if PostgreSQL or Sphinx are enabled. Can either
be 'fulltext' (default) or 'like'. The former is faster and more efficient
but requires the lame old MyISAM engine for MySQL. The latter
will work with InnoDB but could be miserably slow on large
systems. We'll probably add another type sometime in the future,
with our own indexing system (maybe like MediaWiki's).
Troubleshooting
===============

View File

@ -193,7 +193,14 @@ class Memcached_DataObject extends DB_DataObject
// unable to connect to sphinx' search daemon
if (!$connected) {
if ('mysql' === common_config('db', 'type')) {
$search_engine = new MySQLSearch($this, $table);
$type = common_config('search', 'type');
if ($type == 'like') {
$search_engine = new MySQLLikeSearch($this, $table);
} else if ($type == 'fulltext') {
$search_engine = new MySQLSearch($this, $table);
} else {
throw new ServerException('Unknown search type: ' . $type);
}
} else {
$search_engine = new PGSearch($this, $table);
}

View File

@ -228,7 +228,9 @@ $config =
),
'group' =>
array('maxaliases' => 3),
'oohembed' => array('endpoint' => 'http://oohembed.com/oohembed/')
'oohembed' => array('endpoint' => 'http://oohembed.com/oohembed/'),
'search' =>
array('type' => 'fulltext'),
);
$config['db'] = &PEAR::getStaticProperty('DB_DataObject','options');

View File

@ -131,6 +131,28 @@ class MySQLSearch extends SearchEngine
}
}
class MySQLLikeSearch extends SearchEngine
{
function query($q)
{
if ('identica_people' === $this->table) {
$qry = sprintf('(nickname LIKE "%%%1$s%%" OR '.
' fullname LIKE "%%%1$s%%" OR '.
' location LIKE "%%%1$s%%" OR '.
' bio LIKE "%%%1$s%%" OR '.
' homepage LIKE "%%%1$s%%")', addslashes($q));
} else if ('identica_notices' === $this->table) {
$qry = sprintf('content LIKE "%%%1$s%%"', addslashes($q));
} else {
throw new ServerException('Unknown table: ' . $this->table);
}
$this->target->whereAdd($qry);
return true;
}
}
class PGSearch extends SearchEngine
{
function query($q)