예제 #1
0
파일: Query.php 프로젝트: akleiber/search
 /**
  * Execute search and hydrate results if required.
  *
  * @param integer $hydrationMode
  * @throws DoctrineSearchException
  * @return mixed
  */
 public function getResult($hydrationMode = null)
 {
     if ($hydrationMode) {
         $this->hydrationMode = $hydrationMode;
     }
     $classes = array();
     foreach ($this->entityClasses as $entityClass) {
         $classes[] = $this->sm->getClassMetadata($entityClass);
     }
     $resultSet = $this->getSearchManager()->getClient()->search($this->query, $classes);
     // TODO: abstraction of support for different result sets
     if ($resultSet instanceof Elastica\ResultSet) {
         $this->count = $resultSet->getTotalHits();
         $this->facets = $resultSet->getFacets();
         $results = $resultSet->getResults();
     } else {
         $resultClass = get_class($resultSet);
         throw new DoctrineSearchException("Unexpected result set class '{$resultClass}'");
     }
     // Return results depending on hydration mode
     if ($this->hydrationMode == self::HYDRATE_BYPASS) {
         return $resultSet;
     } elseif ($this->hydrationMode == self::HYDRATE_INTERNAL) {
         return $this->sm->getUnitOfWork()->hydrateCollection($classes, $resultSet);
     }
     // Document ids are used to lookup dbms results
     $fn = function ($result) {
         return $result->getId();
     };
     $ids = array_map($fn, $results);
     return $this->getHydrationQuery()->setParameter($this->hydrationParameter, $ids ?: null)->useResultCache($this->useResultCache, $this->cacheLifetime)->getResult($this->hydrationMode);
 }
예제 #2
0
 /**
  * Execute a direct search query on the associated index and type
  *
  * @param object $query
  */
 public function search($query)
 {
     return $this->_sm->getUnitOfWork()->loadCollection(array($this->_class), $query);
 }
 /**
  * Execute a direct search query on the associated index and type
  *
  * @param object $query
  * @return array|\Doctrine\Common\Collections\ArrayCollection|ElasticsearchEntityCollection
  */
 public function search($query)
 {
     $classes = $this->getClassMetadata();
     return $this->_sm->getUnitOfWork()->loadCollection($classes, $query);
 }