Esempio n. 1
0
 /**
  * Get select query
  *
  * @param AbstractQuery $query
  *
  * @return \Solarium\QueryType\Select\Query\Query
  */
 public function getSelectQuery(AbstractQuery $query)
 {
     $selectQuery = $this->solrClientCore->createSelect($query->getOptions());
     $selectQuery->setQuery($query->getQuery());
     $selectQuery->setFilterQueries($query->getFilterQueries());
     $selectQuery->setSorts($query->getSorts());
     $selectQuery->setFields($query->getFields());
     return $selectQuery;
 }
Esempio n. 2
0
 /**
  * {@inheritdoc}
  */
 public function query(AbstractQuery $query)
 {
     $entity = $query->getEntity();
     $runQueryInIndex = $query->getIndex();
     $selectQuery = $this->solrClientCore->createSelect($query->getOptions());
     $selectQuery->setQuery($query->getQuery());
     $selectQuery->setFilterQueries($query->getFilterQueries());
     $selectQuery->setSorts($query->getSorts());
     try {
         $response = $this->solrClientCore->select($selectQuery, $runQueryInIndex);
     } catch (\Exception $e) {
         $errorEvent = new ErrorEvent(null, null, 'query solr');
         $errorEvent->setException($e);
         $this->eventManager->dispatch(Events::ERROR, $errorEvent);
         return array();
     }
     $this->numberOfFoundDocuments = $response->getNumFound();
     if ($this->numberOfFoundDocuments == 0) {
         return array();
     }
     $targetEntity = $entity;
     $mappedEntities = array();
     foreach ($response as $document) {
         $mappedEntities[] = $this->entityMapper->toEntity($document, $targetEntity);
     }
     return $mappedEntities;
 }