SphinxClient::SetFilterRange PHP Method

SetFilterRange() public method

only match records if $attribute value is beetwen $min and $max (inclusive)
public SetFilterRange ( $attribute, $min, $max, $exclude = false )
    function SetFilterRange($attribute, $min, $max, $exclude = false)
    {
        assert(is_string($attribute));
        assert(is_numeric($min));
        assert(is_numeric($max));
        assert($min <= $max);
        $this->_filters[] = array("type" => SPH_FILTER_RANGE, "attr" => $attribute, "exclude" => $exclude, "min" => $min, "max" => $max);
    }

Usage Example

 private function get_sugg_trigrams($word, SearchEngineOptions $options)
 {
     $trigrams = $this->BuildTrigrams($word);
     $query = "\"{$trigrams}\"/1";
     $len = strlen($word);
     $this->resetSphinx();
     $this->suggestionClient->SetMatchMode(SPH_MATCH_EXTENDED2);
     $this->suggestionClient->SetRankingMode(SPH_RANK_WORDCOUNT);
     $this->suggestionClient->SetFilterRange("len", $len - 2, $len + 4);
     $this->suggestionClient->SetSortMode(SPH_SORT_EXTENDED, "@weight DESC");
     $this->suggestionClient->SetLimits(0, 10);
     $indexes = [];
     foreach ($options->getDataboxes() as $databox) {
         $indexes[] = 'suggest' . $this->CRCdatabox($databox);
     }
     $index = implode(',', $indexes);
     $res = $this->suggestionClient->Query($query, $index);
     if ($this->suggestionClient->Status() === false) {
         return [];
     }
     if (!$res || !isset($res["matches"])) {
         return [];
     }
     $words = [];
     foreach ($res["matches"] as $match) {
         $words[] = $match['attrs']['keyword'];
     }
     return $words;
 }
All Usage Examples Of SphinxClient::SetFilterRange