示例#1
0
 /**
  * @brief set query filters, SQL-like syntax - 'additional where_condition'
  * @param array $filters
  * @return $this chain
  */
 public function filters($filters)
 {
     $this->criteria->filters = $filters;
     //set filters
     if ($filters && is_array($filters)) {
         foreach ($filters as $fil => $vol) {
             // geo filter
             if ($fil == 'geo') {
                 $min = (double) (isset($vol['min']) ? $vol['min'] : 0);
                 $point = explode(' ', str_replace('POINT(', '', trim($vol['point'], ')')));
                 $this->client->setGeoAnchor('latitude', 'longitude', (double) $point[1] * (pi() / 180), (double) $point[0] * (pi() / 180));
                 $this->client->setFilterFloatRange('@geodist', $min, (double) $vol['buffer']);
                 // usual filter
             }
             if ($fil == 'range') {
                 //   $point = explode(' ', str_replace('POINT(', '', trim($vol['point'], ')')));
                 // $this->client->setGeoAnchor('latitude', 'longitude', (float) $point[1] * ( pi() / 180 ), (float) $point[0] * ( pi() / 180 ));
                 if (is_array($vol)) {
                     foreach ($vol as $kk => $vv) {
                         $min = (double) (isset($vv['min']) ? $vv['min'] : 0);
                         $this->client->setFilterFloatRange($kk, $min, (double) $vv['max']);
                     }
                 }
                 // usual filter
             } else {
                 if ($vol) {
                     $this->client->SetFilter($fil, is_array($vol) ? $vol : array($vol));
                 }
             }
         }
     }
     return $this;
 }
 /**
  * Binds the filter to a SphinxClient instance
  *
  * @param \SphinxClient $sphinx
  *
  * @return FilterFloatRange
  */
 public function bindToSphinx(\SphinxClient $sphinx)
 {
     $sphinx->setFilterFloatRange($this->name, $this->min, $this->max, $this->exclude);
     return $this;
 }