Beispiel #1
0
 function saveIndex()
 {
     try {
         $elastic = new TweetElastic();
         $elastic->primaryKey = $this->id;
         $params = $this->getAttributes();
         $params['position'] = ['lat' => $params['latitude'], 'lon' => $params['longitude']];
         unset($params['id']);
         unset($params['latitude']);
         unset($params['longitude']);
         $elastic->setAttributes($params, false);
         $elastic->save();
     } catch (\Exception $e) {
     }
 }
Beispiel #2
0
 public function actionSearch()
 {
     $list = [];
     try {
         Yii::$app->errorHandler->unregister();
         $list = TweetElastic::find()->filter($_POST['filter'])->all();
     } catch (\Exception $e) {
         Yii::$app->errorHandler->exception->type = null;
         Yii::$app->errorHandler->register();
         // var_dump($_POST['filter']['geo_bounding_box']['position']['bottom_right']['lat']);
         $list = Tweet::find()->where('latitude > :latitude', [':latitude' => $_POST['filter']['geo_bounding_box']['position']['bottom_right']['lat']])->andWhere('latitude < :latitude2', [':latitude2' => $_POST['filter']['geo_bounding_box']['position']['top_left']['lat']])->andWhere('longitude < :longitude', [':longitude' => $_POST['filter']['geo_bounding_box']['position']['bottom_right']['lon']])->andWhere('longitude > :longitude2', [':longitude2' => $_POST['filter']['geo_bounding_box']['position']['top_left']['lon']])->all();
     }
     $response = [];
     foreach ($list as $tweet) {
         $response[] = $tweet->getAttributes();
     }
     return json_encode($response);
 }