X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=plugins%2FSphinxSearch%2Fsphinxsearch.php;h=607ac76d2758de203cd5aca3c32fd4a518855c3a;hb=96e0867d4c52647af4455117f27e20a23aac3ec9;hp=1ce9bfd72d149ffbf727b083e1a43375096b0f3c;hpb=e36399974e6ccd1ee3e53bfffa3c34edaf8bd488;p=quix0rs-gnu-social.git diff --git a/plugins/SphinxSearch/sphinxsearch.php b/plugins/SphinxSearch/sphinxsearch.php index 1ce9bfd72d..607ac76d27 100644 --- a/plugins/SphinxSearch/sphinxsearch.php +++ b/plugins/SphinxSearch/sphinxsearch.php @@ -65,6 +65,9 @@ class SphinxSearch extends SearchEngine function query($q) { $result = $this->sphinx->query($q, $this->remote_table()); + if ($result === false) { + throw new ServerException($this->sphinx->getLastError()); + } if (!isset($result['matches'])) return false; $id_set = join(', ', array_keys($result['matches'])); $this->target->whereAdd("id in ($id_set)"); @@ -73,9 +76,39 @@ class SphinxSearch extends SearchEngine function set_sort_mode($mode) { - if ('chron' === $mode) { + switch ($mode) { + case 'chron': + $this->sphinx->SetSortMode(SPH_SORT_ATTR_DESC, 'created_ts'); + return $this->target->orderBy('id desc'); + break; + case 'reverse_chron': + $this->sphinx->SetSortMode(SPH_SORT_ATTR_ASC, 'created_ts'); + return $this->target->orderBy('id asc'); + break; + case 'nickname_desc': + if ($this->table != 'profile') { + throw new Exception( + 'nickname_desc sort mode can only be use when searching profile.' + ); + } else { + $this->sphinx->SetSortMode(SPH_SORT_ATTR_DESC, 'nickname'); + return $this->target->orderBy('id desc'); + } + break; + case 'nickname_asc': + if ($this->table != 'profile') { + throw new Exception( + 'nickname_desc sort mode can only be use when searching profile.' + ); + } else { + $this->sphinx->SetSortMode(SPH_SORT_ATTR_ASC, 'nickname'); + return $this->target->orderBy('id asc'); + } + break; + default: $this->sphinx->SetSortMode(SPH_SORT_ATTR_DESC, 'created_ts'); return $this->target->orderBy('id desc'); + break; } }