コード例 #1
0
 public function testIfWillFindDocument()
 {
     $model = new SimpleModel();
     $model->_id = new MongoId();
     $model->title = 'New York, Tokyo, Los Angeles, Paris, Shanghai';
     $im = new IndexManager($model);
     $im->index();
     $val = $im->get();
     // Need to wait here, or it will fail...
     sleep(1);
     $q = new QueryBuilder($model);
     /* @var $result SimpleModel[] */
     $result = $q->search('tokyo');
     codecept_debug($result);
     $this->assertTrue(count($result) > 0);
     unset($result);
 }
コード例 #2
0
ファイル: SearchProvider.php プロジェクト: maslosoft/manganel
 protected function fetchData()
 {
     $criteria = $this->configureFetch();
     /**
      * TODO Refactor this into SearchFinder class
      */
     $qb = new QueryBuilder();
     if ($criteria instanceof SearchCriteria) {
         $models = $criteria->getModels();
         if (!empty($models)) {
             $qb->add($models);
         }
     }
     $model = $this->getModel();
     if (!Event::handled($model, FinderInterface::EventBeforeFind)) {
         return [];
     }
     $modelCriteria = $model->getDbCriteria();
     $criteria->mergeWith($modelCriteria);
     if (!empty($model)) {
         $qb->add($model);
     }
     $qb->setCriteria($criteria);
     $rawResults = $qb->search($criteria->getSearch());
     $results = [];
     foreach ($rawResults as $data) {
         $model = SearchArray::toModel($data['_source']);
         if ($model instanceof IndexAwareInterface) {
             $model->setIndex($data['_index']);
         }
         if ($model instanceof ScoreAwareInterface) {
             $model->setScore($data['_score']);
         }
         $results[] = $model;
     }
     return $results;
 }