示例#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;
 }
 /**
  * @brief 위치 기반 Sphinx 검색 부분 (외부/내부 호출용..)
  * @param $document_srl 문서 번호
  * @param $lat 위도
  * @param $lon 경도
  * @return 검색된 결과 리스트
  */
 function getSphinxSearchedResult($document_srl, $lat, $lon)
 {
     $s = new SphinxClient();
     $oModuleModel =& getModel('module');
     $config = $oModuleModel->getModuleConfig('aroundmap');
     $s->setServer($config->serverName, $config->serverPort);
     $s->setLimits(0, 10);
     $s->setMatchMode(SPH_MATCH_ALL);
     $s->SetSortMode(SPH_SORT_EXTENDED, '@geodist ASC');
     $s->setFilter("document_srl", array($document_srl), true);
     $s->SetFilterFloatRange("@geodist", 0, 10000);
     $s->setMaxQueryTime(3);
     $s->setGeoAnchor("lat", "lon", (double) deg2rad($lat), (double) deg2rad($lon));
     $result = $s->query("", "idx_aroundmap");
     $ret = array();
     if ($result[total_found] > 0) {
         $ret = $result[matches];
     }
     return $ret;
 }