Sphinx\SphinxClient::setFilterRange PHP Method

setFilterRange() public method

Set range filter; only match records if $attribute value between $min and $max (inclusive)
public setFilterRange ( string $attribute, integer $min, integer $max, boolean $exclude = false ) : SphinxClient
$attribute string attribute name
$min integer minimum attribute value
$max integer maximum attribute value
$exclude boolean whether the filter is exclusive or inclusive
return SphinxClient
    public function setFilterRange($attribute, $min, $max, $exclude = false)
    {
        if (!is_string($attribute)) {
            throw new \InvalidArgumentException('Attribute name must be a string.');
        }
        if (!is_numeric($min)) {
            throw new \InvalidArgumentException('Minimum value must be numeric.');
        }
        if (!is_numeric($max)) {
            throw new \InvalidArgumentException('Maximum value must be numeric.');
        }
        if ($min > $max) {
            throw new \InvalidArgumentException('Minimum value cannot be larger than maximum value.');
        }
        $exclude = (bool) $exclude;
        $this->filters[] = array('type' => self::SPH_FILTER_RANGE, 'attr' => $attribute, 'exclude' => $exclude, 'min' => $min, 'max' => $max);
        return $this;
    }

Usage Example

Example #1
0
 public function testFilterRangeExclude()
 {
     $sphinx = new SphinxClient();
     $sphinx->setFilterRange('attr1', 4, 5, true);
     $results = $sphinx->query('bb');
     $this->assertEquals($results['total'], 3);
 }
All Usage Examples Of Sphinx\SphinxClient::setFilterRange