Sphinx\SphinxClient::setSortMode PHP Method

setSortMode() public method

Set matches sorting mode
public setSortMode ( integer $mode, string $sortby = '' ) : SphinxClient
$mode integer
$sortby string
return SphinxClient
    public function setSortMode($mode, $sortby = '')
    {
        if (!in_array($mode, array(self::SPH_SORT_RELEVANCE, self::SPH_SORT_ATTR_DESC, self::SPH_SORT_ATTR_ASC, self::SPH_SORT_TIME_SEGMENTS, self::SPH_SORT_EXTENDED, self::SPH_SORT_EXPR))) {
            throw new \InvalidArgumentException('Sorting mode is invalid.');
        }
        if (!is_string($sortby)) {
            throw new \InvalidArgumentException('Sorting expression must be a string.');
        }
        if ($mode !== self::SPH_SORT_RELEVANCE && !$sortby) {
            throw new \InvalidArgumentException('Current sorting mode must have a sorting expression.');
        }
        $this->sort = $mode;
        $this->sortby = $sortby;
        return $this;
    }

Usage Example

Example #1
0
 /**
  * @expectedException \InvalidArgumentException
  */
 public function testSetSortModeWithNonRelevanceSortWithoutExpressionShouldThrowException()
 {
     $sphinx = new SphinxClient();
     $sphinx->setSortMode(SphinxClient::SPH_SORT_EXPR);
 }
All Usage Examples Of Sphinx\SphinxClient::setSortMode