示例#1
0
 /**
  * @param DocumentInterface $document
  * @param string            $index
  */
 public function delete(DocumentInterface $document, $index)
 {
     $deleteQuery = new FindByIdentifierQuery();
     $deleteQuery->setDocument($document);
     $delete = $this->solariumClient->createUpdate();
     $delete->addDeleteQuery($deleteQuery->getQuery());
     $delete->addCommit();
     $this->applyQuery($delete, $index);
 }
 public function testGetQuery_IdMissing()
 {
     $document = new \SolrInputDocument();
     $query = new FindByIdentifierQuery($document);
     try {
         $queryString = $query->getQueryString();
         $this->fail('an exception should be thrown');
     } catch (\RuntimeException $e) {
         $this->assertEquals('id should not be null', $e->getMessage());
     }
 }
示例#3
0
 /**
  * @param DocumentInterface $document
  * @param string            $index
  */
 public function delete(DocumentInterface $document, $index)
 {
     $documentFields = $document->getFields();
     $documentKey = $documentFields[MetaInformationInterface::DOCUMENT_KEY_FIELD_NAME];
     $deleteQuery = new FindByIdentifierQuery();
     $deleteQuery->setDocument($document);
     $deleteQuery->setDocumentKey($documentKey);
     $delete = $this->solariumClient->createUpdate();
     $delete->addDeleteQuery($deleteQuery->getQuery());
     $delete->addCommit();
     $this->applyQuery($delete, $index);
 }
示例#4
0
 public function find($id)
 {
     $this->entity->setId($id);
     $mapper = $this->solr->getMapper();
     $mapper->setMappingCommand($this->solr->getCommandFactory()->get('all'));
     $metaInformation = $this->solr->getMetaFactory()->loadInformation($this->entity);
     $document = $mapper->toDocument($metaInformation);
     $query = new FindByIdentifierQuery($document);
     $query->setEntity($this->entity);
     $found = $this->solr->query($query);
     if (count($found) == 0) {
         return null;
     }
     return array_pop($found);
 }
示例#5
0
 /**
  * @param object $entity
  */
 public function removeDocument($entity)
 {
     $command = $this->commandFactory->get('identifier');
     $this->entityMapper->setMappingCommand($command);
     $metaInformations = $this->metaInformationFactory->loadInformation($entity);
     if ($document = $this->entityMapper->toDocument($metaInformations)) {
         $deleteQuery = new FindByIdentifierQuery($document);
         $queryString = $deleteQuery->getQueryString();
         try {
             $response = $this->solrClient->deleteByQuery($queryString);
             $this->solrClient->commit();
         } catch (\Exception $e) {
             $errorEvent = new ErrorEvent(null, null, 'delete-document');
             $errorEvent->setException($e);
             $this->eventManager->handle(EventManager::ERROR, $errorEvent);
         }
         $this->eventManager->handle(EventManager::DELETE, new Event($this->solrClient, $metaInformations));
     }
 }
 /**
  * @expectedException \RuntimeException
  * @expectedExceptionMessage id should not be null
  */
 public function testGetQuery_IdMissing()
 {
     $query = new FindByIdentifierQuery();
     $query->setDocument(new Document());
     $query->getQuery();
 }