示例#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;
 }
示例#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;
 }
示例#3
0
 /**
  * @param SolrFacade $solr
  */
 public function __construct(SolrFacade $solr)
 {
     parent::__construct();
     $this->solrFacade = $solr;
 }
示例#4
0
 /**
  * @return string
  */
 public function getQuery()
 {
     if ($this->customQuery) {
         parent::setQuery($this->customQuery);
         return $this->customQuery;
     }
     $term = '';
     if (count($this->searchTerms) == 0) {
         $query = '*:*';
         parent::setQuery($query);
         return $query;
     }
     $logicOperator = 'AND';
     if (!$this->useAndOperator) {
         $logicOperator = 'OR';
     }
     $termCount = 1;
     foreach ($this->searchTerms as $fieldName => $fieldValue) {
         $fieldValue = $this->querifyFieldValue($fieldValue);
         $term .= $fieldName . ':' . $fieldValue;
         if ($termCount < count($this->searchTerms)) {
             $term .= ' ' . $logicOperator . ' ';
         }
         $termCount++;
     }
     $this->setQuery($term);
     return $term;
 }