/** * {@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; }
public function testToEntity_ConcreteDocumentClass_WithDoctrine() { $targetEntity = new ValidTestEntity(); $this->indexHydrator->expects($this->once())->method('hydrate')->will($this->returnValue($targetEntity)); $this->doctrineHydrator->expects($this->once())->method('hydrate')->will($this->returnValue($targetEntity)); $mapper = new \FS\SolrBundle\Doctrine\Mapper\EntityMapper($this->doctrineHydrator, $this->indexHydrator, $this->metaInformationFactory); $mapper->setHydrationMode(HydrationModes::HYDRATE_DOCTRINE); $entity = $mapper->toEntity(new Document(array()), $targetEntity); $this->assertTrue($entity instanceof $targetEntity); }
public function testToEntity() { $obj = new SolrDocumentStub(array('id' => 1, 'title_t' => 'foo')); $targetEntity = new ValidTestEntity(); $mapper = new \FS\SolrBundle\Doctrine\Mapper\EntityMapper(); $entity = $mapper->toEntity($obj, $targetEntity); $this->assertTrue($entity instanceof $targetEntity); $this->assertEquals(1, $entity->getId()); $this->assertEquals('foo', $entity->getTitle()); }
/** * @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; }