예제 #1
0
 /**
  * {@inheritdoc}
  */
 public function findBy(array $args)
 {
     $query = $this->solr->createQuery($this->entity);
     foreach ($args as $fieldName => $fieldValue) {
         $query->addSearchTerm($fieldName, $fieldValue);
     }
     return $this->solr->query($query);
 }
예제 #2
0
 /**
  * @param LifecycleEventArgs $args
  */
 public function postUpdate(LifecycleEventArgs $args)
 {
     $entity = $args->getEntity();
     try {
         $this->solr->updateDocument($entity);
     } catch (\RuntimeException $e) {
     }
 }
예제 #3
0
 /**
  * @param LifecycleEventArgs $args
  */
 public function postPersist(LifecycleEventArgs $args)
 {
     $entity = $args->getDocument();
     try {
         $this->solr->addDocument($entity);
     } catch (\RuntimeException $e) {
     }
 }
예제 #4
0
 /**
  * @param LifecycleEventArgs $args
  */
 public function preRemove(LifecycleEventArgs $args)
 {
     $entity = $args->getDocument();
     try {
         $this->solr->removeDocument($entity);
     } catch (\RuntimeException $e) {
     }
 }
 /**
  * @param LifecycleEventArgs $args
  */
 public function postUpdate(LifecycleEventArgs $args)
 {
     try {
         $entity = $args->getEntity();
         $metaInformation = $this->solr->getMetaFactory()->loadInformation($entity);
         $entity = EntityHelper::customizeEntity($entity, $metaInformation);
         $this->solr->updateDocument($entity);
         EntityHelper::normalizationEntity($entity, $metaInformation);
     } catch (\RuntimeException $e) {
     }
 }
예제 #6
0
 /**
  * @test
  */
 public function removeDocumentFromAllCores()
 {
     $metaInformation = MetaTestInformationFactory::getMetaInformation();
     $metaInformation->setIndex('*');
     $this->setupMetaFactoryLoadOneCompleteInformation($metaInformation);
     $this->mapper->expects($this->once())->method('toDocument')->will($this->returnValue(new DocumentStub()));
     $this->solrClientFake->expects($this->once())->method('getEndpoints')->will($this->returnValue(array('core0' => array(), 'core1' => array())));
     $deleteQuery = $this->getMock('Solarium\\QueryType\\Update\\Query\\Query', array(), array(), '', false);
     $deleteQuery->expects($this->once())->method('addDeleteQuery')->with($this->isType('string'));
     $deleteQuery->expects($this->once())->method('addCommit');
     $this->solrClientFake->expects($this->once())->method('createUpdate')->will($this->returnValue($deleteQuery));
     $this->solrClientFake->expects($this->exactly(2))->method('update');
     $solr = new Solr($this->solrClientFake, $this->commandFactory, $this->eventDispatcher, $this->metaFactory, $this->mapper);
     $solr->removeDocument(new ValidTestEntity());
 }
예제 #7
0
 /**
  * @param string $searchQuery
  * @param array $sort
  * @param int $offset
  * @param int $limit
  * @return array
  */
 public function findInIndex($searchQuery = "", $sort = [], $offset = 0, $limit = 0)
 {
     $client = $this->solr_client->getClient();
     $query = $client->createSelect();
     $query->setQuery($searchQuery);
     if (!empty($sort)) {
         foreach ($sort as $key => $value) {
             $query->addSort($key, $value);
         }
     }
     if (!empty($limit)) {
         $query->setRows($limit);
     }
     if (!empty($offset)) {
         $query->setStart($offset);
     }
     $resultset = $client->select($query);
     $result = [];
     /** @var Document $document */
     foreach ($resultset as $document) {
         $result[] = ArrayHelper::createArrayFromDocument($document);
     }
     return $result;
 }
예제 #8
0
 /**
  * {@inheritdoc}
  */
 public function findOneBy(array $args)
 {
     $metaInformation = $this->solr->getMetaFactory()->loadInformation($this->entity);
     $query = $this->solr->createQuery($this->entity);
     $query->setHydrationMode($this->hydrationMode);
     $query->setRows(1);
     $query->setUseAndOperator(true);
     $query->addSearchTerm('id', $metaInformation->getDocumentName() . '_*');
     $query->setQueryDefaultField('id');
     $helper = $query->getHelper();
     foreach ($args as $fieldName => $fieldValue) {
         $fieldValue = $helper->escapeTerm($fieldValue);
         $query->addSearchTerm($fieldName, $fieldValue);
     }
     $found = $this->solr->query($query);
     return array_pop($found);
 }
예제 #9
0
 /**
  * @When /^I add these entities to Solr$/
  */
 public function iAddThisEntityToSolr()
 {
     foreach ($this->entities as $entity) {
         $this->solr->addDocument($entity);
     }
 }
예제 #10
0
 /**
  * @When /^I delete the entity$/
  */
 public function iDeleteTheEntity()
 {
     $this->solr->removeDocument($this->entity);
 }
예제 #11
0
 /**
  * @expectedException \BadMethodCallException
  */
 public function testAddEntity_FilteredEntityWithUnknownCallback()
 {
     $this->assertUpdateQueryWasNotExecuted();
     $this->eventDispatcher->expects($this->never())->method('dispatch');
     $information = MetaTestInformationFactory::getMetaInformation();
     $information->setSynchronizationCallback('shouldBeIndex');
     $this->setupMetaFactoryLoadOneCompleteInformation($information);
     $solr = new Solr($this->solrClientFake, $this->commandFactory, $this->eventDispatcher, $this->metaFactory, $this->mapper);
     $solr->addDocument(new InvalidTestEntityFiltered());
 }
예제 #12
0
 /**
  * @inheritdoc
  */
 public function remove($entity)
 {
     $repo = $this->modelManager->get($this->getModel());
     $solrRepo = $this->solr->getRepository($repo->getClassName());
     $solrRepo->delete($entity);
 }