]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - lib/search_engines.php
.inc.php please ...
[quix0rs-gnu-social.git] / lib / search_engines.php
index 19703e03fd81aa983aa710cc7af20242aa32b7a7..6014c89923e302e8584fff2f5f0b5aac555d394f 100644 (file)
@@ -41,8 +41,35 @@ class SearchEngine
 
     function set_sort_mode($mode)
     {
-        if ('chron' === $mode)
-            return $this->target->orderBy('created desc');
+        switch ($mode) {
+        case 'chron':
+            return $this->target->orderBy('created DESC');
+            break;
+        case 'reverse_chron':
+            return $this->target->orderBy('created ASC');
+            break;
+        case 'nickname_desc':
+            if ($this->table != 'profile') {
+                throw new Exception(
+                    'nickname_desc sort mode can only be use when searching profile.'
+                );
+            } else {
+                return $this->target->orderBy('nickname DESC');
+            }
+            break;
+        case 'nickname_asc':
+            if ($this->table != 'profile') {
+                throw new Exception(
+                    'nickname_desc sort mode can only be use when searching profile.'
+                );
+            } else {
+                return $this->target->orderBy('nickname ASC');
+            }
+            break;
+        default:
+            return $this->target->orderBy('created DESC');
+            break;
+        }
     }
 }
 
@@ -57,7 +84,6 @@ class MySQLSearch extends SearchEngine
                 $this->target->whereAdd('MATCH(nickname, fullname, location, bio, homepage) ' .
                                         'AGAINST (\''.$this->target->escape(strtolower($q)).'\' IN BOOLEAN MODE)', 'OR');
             }
-            return true;
         } else if ('notice' === $this->table) {
 
             // Don't show imported notices
@@ -73,10 +99,11 @@ class MySQLSearch extends SearchEngine
                                          'AGAINST (\''.$this->target->escape($q).'\' IN BOOLEAN MODE)');
             }
 
-            return true;
         } else {
             throw new ServerException('Unknown table: ' . $this->table);
         }
+
+        return true;
     }
 }