Sphinx\SphinxClient::setFilterFloatRange PHP Method

setFilterFloatRange() public method

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

Usage Example

 public function testFilterFloatRangeExclude()
 {
     $sphinx = new SphinxClient();
     $sphinx->setFilterFloatRange('lat', 0.2, 0.4, true);
     $results = $sphinx->query('bb');
     $this->assertEquals($results['total'], 2);
 }
All Usage Examples Of Sphinx\SphinxClient::setFilterFloatRange