public function setGroupBy($attribute, $func, $groupsort = '@group desc')
{
if (!is_string($attribute)) {
throw new \InvalidArgumentException('Attribute name must be a string.');
}
if (!is_string($groupsort)) {
throw new \InvalidArgumentException('Group sorting clause must be a string.');
}
if (!in_array($func, array(self::SPH_GROUPBY_DAY, self::SPH_GROUPBY_WEEK, self::SPH_GROUPBY_MONTH, self::SPH_GROUPBY_YEAR, self::SPH_GROUPBY_ATTR, self::SPH_GROUPBY_ATTRPAIR))) {
throw new \InvalidArgumentException('Grouping function is invalid.');
}
$this->groupby = $attribute;
$this->groupfunc = $func;
$this->groupsort = $groupsort;
return $this;
}
public function testUpdateAttributes() { $sphinx = new SphinxClient(); $sphinx->setGroupBy('attr1', SphinxClient::SPH_GROUPBY_ATTR); $sphinx->updateAttributes('sphinxtest', array('attr1'), array(1 => array(10), 2 => array(10), 3 => array(20), 4 => array(20))); $results = $sphinx->query('bb'); $this->assertEquals($results['total'], 3); // restore attributes $sphinx->updateAttributes('sphinxtest', array('attr1'), array(1 => array(2), 2 => array(4), 3 => array(1), 4 => array(5))); }