]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - lib/search_engines.php
Updated Cloudy theme default avatars and minor CSS
[quix0rs-gnu-social.git] / lib / search_engines.php
index e96570d63bd6a6ffa04fc4c6afb95253f52939a5..7b9dbb6182543e9e14969f7564c336cddc867350 100644 (file)
@@ -19,7 +19,8 @@
 
 if (!defined('LACONICA')) { exit(1); }
 
-class SearchEngine {
+class SearchEngine
+{
     protected $target;
     protected $table;
 
@@ -45,7 +46,8 @@ class SearchEngine {
     }
 }
 
-class SphinxSearch extends SearchEngine {
+class SphinxSearch extends SearchEngine
+{
     private $sphinx;
     private $connected;
 
@@ -72,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);
@@ -103,25 +105,43 @@ class SphinxSearch extends SearchEngine {
     }
 }
 
-class MySQLSearch extends SearchEngine {
+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);
+        }
     }
 }
 
-class PGSearch extends SearchEngine {
+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);
+        }
     }
 }