Example #1
0
 /**
  * @return array found entities
  */
 public function query(AbstractQuery $query)
 {
     $solrQuery = $query->getSolrQuery();
     try {
         $response = $this->solrClient->query($solrQuery);
     } catch (\Exception $e) {
         return array();
     }
     $response = $response->getResponse();
     if (!array_key_exists('response', $response)) {
         return array();
     }
     if ($response['response']['docs'] == false) {
         return array();
     }
     $targetEntity = $query->getEntity();
     $mappedEntities = array();
     foreach ($response['response']['docs'] as $document) {
         $mappedEntities[] = $this->entityMapper->toEntity($document, $targetEntity);
     }
     return $mappedEntities;
 }
Example #2
0
 /**
  * {@inheritdoc}
  */
 public function query(AbstractQuery $query)
 {
     $entity = $query->getEntity();
     $queryString = $query->getQuery();
     $runQueryInIndex = $query->getIndex();
     $query = $this->solrClientCore->createSelect($query->getOptions());
     $query->setQuery($queryString);
     try {
         $response = $this->solrClientCore->select($query, $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;
 }