X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=lib%2Fsearch_engines.php;h=7b9dbb6182543e9e14969f7564c336cddc867350;hb=6658e2a2ee9517bebd59cf69d7483e6eda691b4e;hp=559107910cef885bccb87a4687b8ab0b2dcae707;hpb=b264c03d32d04d7a33d28a5830848660f4484943;p=quix0rs-gnu-social.git diff --git a/lib/search_engines.php b/lib/search_engines.php index 559107910c..7b9dbb6182 100644 --- a/lib/search_engines.php +++ b/lib/search_engines.php @@ -74,7 +74,7 @@ class SphinxSearch extends SearchEngine { //FIXME without LARGEST_POSSIBLE, the most recent results aren't returned // this probably has a large impact on performance - $LARGEST_POSSIBLE = 1e6; + $LARGEST_POSSIBLE = 1e6; if ($rss) { $this->sphinx->setLimits($offset, $count, $count, $LARGEST_POSSIBLE); @@ -109,12 +109,25 @@ class MySQLSearch extends SearchEngine { function query($q) { - if ('identica_people' === $this->table) - return $this->target->whereAdd('MATCH(nickname, fullname, location, bio, homepage) ' . - 'against (\''.addslashes($q).'\')'); - if ('identica_notices' === $this->table) - return $this->target->whereAdd('MATCH(content) ' . - 'against (\''.addslashes($q).'\')'); + if ('identica_people' === $this->table) { + $this->target->whereAdd('MATCH(nickname, fullname, location, bio, homepage) ' . + 'AGAINST (\''.addslashes($q).'\' IN BOOLEAN MODE)'); + if (strtolower($q) != $q) { + $this->target->whereAdd('MATCH(nickname, fullname, location, bio, homepage) ' . + 'AGAINST (\''.addslashes(strtolower($q)).'\' IN BOOLEAN MODE)', 'OR'); + } + return true; + } else if ('identica_notices' === $this->table) { + $this->target->whereAdd('MATCH(content) ' . + 'AGAINST (\''.addslashes($q).'\' IN BOOLEAN MODE)'); + if (strtolower($q) != $q) { + $this->target->whereAdd('MATCH(content) ' . + 'AGAINST (\''.addslashes(strtolower($q)).'\' IN BOOLEAN MODE)', 'OR'); + } + return true; + } else { + throw new ServerException('Unknown table: ' . $this->table); + } } } @@ -122,10 +135,13 @@ class PGSearch extends SearchEngine { function query($q) { - if ('identica_people' === $this->table) + if ('identica_people' === $this->table) { return $this->target->whereAdd('textsearch @@ plainto_tsquery(\''.addslashes($q).'\')'); - if ('identica_notices' === $this->table) + } else if ('identica_notices' === $this->table) { return $this->target->whereAdd('to_tsvector(\'english\', content) @@ plainto_tsquery(\''.addslashes($q).'\')'); + } else { + throw new ServerException('Unknown table: ' . $this->table); + } } }