コード例 #1
0
ファイル: Client.php プロジェクト: wizbit/SolrBundle
 /**
  * Runs a *:* delete query on all cores
  */
 public function clearCores()
 {
     $delete = $this->solariumClient->createUpdate();
     $delete->addDeleteQuery('*:*');
     $delete->addCommit();
     $this->applyOnAllCores($delete);
 }
コード例 #2
0
ファイル: SolrStorage.php プロジェクト: systream/repository
 /**
  * @param SavableModelInterface $model
  * @throws CouldNotPurgeException
  */
 public function purge(SavableModelInterface $model)
 {
     $update = $this->solrClient->createUpdate();
     $update->addDeleteById($model->getId());
     $update->addCommit();
     $result = $this->solrClient->update($update);
     if ($result->getStatus() != 0) {
         throw new CouldNotPurgeException('Model could not purge: ' . $result->getResponse()->getStatusMessage());
     }
 }
 /**
  * {@inheritDoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $query = $input->getOption('query') ?: '*:*';
     $this->logger->info('Starting delete query "{query}"', array('query' => $query));
     $updateCommand = $this->solrClient->createUpdate();
     $updateCommand->addDeleteQuery($query);
     $updateCommand->addCommit();
     /** @var Result $result */
     $result = $this->solrClient->execute($updateCommand);
     $this->logger->info('Finished delete query "{query}", status: {status}, duration: {duration}', array('query' => $query, 'status' => $result->getStatus(), 'duration' => $result->getQueryTime()));
 }
コード例 #4
0
 /**
  * This method is a hook e.g. to notice an external change tracker that all the in memory synchronization is
  * finished, i.e. can be persisted (e.g. by calling an entity manager's flush()).
  */
 public function commit()
 {
     if (count($this->deletedDocumentIds) === 0 && count($this->newOrUpdatedDocuments) === 0) {
         return;
     }
     $this->messages[] = "Flushing " . count($this->newOrUpdatedDocuments) . " inserts or updates and " . count($this->deletedDocumentIds) . " deletes";
     $update = $this->solrClient->createUpdate();
     if ($this->deletedDocumentIds) {
         $update->addDeleteByIds($this->deletedDocumentIds);
     }
     if ($this->newOrUpdatedDocuments) {
         $update->addDocuments($this->newOrUpdatedDocuments);
     }
     $update->addCommit();
     $this->solrClient->execute($update);
     $this->deletedDocumentIds = array();
     $this->newOrUpdatedDocuments = array();
     /*
      * Manually trigger garbage collection
      * \Solarium\QueryType\Update\Query\Document\Document might hold a reference
      * to a "helper" object \Solarium\Core\Query\Helper, which in turn references
      * back the document. This circle prevents the normal, refcount-based GC from
      * cleaning up the processed Document instances after we release them.
      *
      * To prevent memory exhaustion, we start a GC cycle collection run.
      */
     $update = null;
     gc_collect_cycles();
 }
コード例 #5
0
ファイル: SolrAdapter.php プロジェクト: andreas-serlo/athene2
 /**
  * {@inheritDoc}
  */
 public function erase()
 {
     $update = $this->update = $this->client->createUpdate();
     $update->addDeleteQuery('*:*');
     $update->addCommit();
     $this->flush();
 }
コード例 #6
0
 /**
  * Remove document from solr by ID
  * @param array $metadata
  * @param string $document_id
  */
 public function deleteDocumentById($metadata, $document_id)
 {
     $this->setCoreNameFromMetadata($metadata);
     $updateQuery = $this->client->createUpdate();
     $updateQuery->addDeleteById($document_id);
     $this->client->update($updateQuery);
 }
コード例 #7
0
ファイル: Solr.php プロジェクト: cpliakas/solr-search-engine
 /**
  * Implements Search::Framework::SearchEngineAbstract::delete().
  *
  * @return \Solarium\QueryType\Update\Result
  */
 public function delete()
 {
     $update = $this->_client->createUpdate();
     $update->addDeleteQuery('*:*');
     $update->addCommit();
     return $this->_client->update($update);
 }
 private function flush()
 {
     $this->logger->info("Flushing {numberInsertsUpdates} inserts or updates and {numberDeletes} deletes", array('numberInsertsUpdates' => count($this->newOrUpdatedDocuments), 'numberDeletes' => count($this->deletedDocumentIds)));
     if (count($this->deletedDocumentIds) === 0 && count($this->newOrUpdatedDocuments) === 0) {
         return;
     }
     $update = $this->solrClient->createUpdate();
     if ($this->deletedDocumentIds) {
         $update->addDeleteByIds($this->deletedDocumentIds);
     }
     if ($this->newOrUpdatedDocuments) {
         $update->addDocuments($this->newOrUpdatedDocuments);
     }
     $update->addCommit();
     $this->solrClient->execute($update);
     $this->deletedDocumentIds = array();
     $this->newOrUpdatedDocuments = array();
     $this->logger->debug("Flushed");
     /*
      * Manually trigger garbage collection
      * \Solarium\QueryType\Update\Query\Document\Document might hold a reference
      * to a "helper" object \Solarium\Core\Query\Helper, which in turn references
      * back the document. This circle prevents the normal, refcount-based GC from
      * cleaning up the processed Document instances after we release them.
      *
      * To prevent memory exhaustion, we start a GC cycle collection run.
      */
     $update = null;
     gc_collect_cycles();
 }
コード例 #9
0
 /**
  * Remove document from solr.
  *
  * @param \PhpAmqpLib\Message\AMQPMessage $message
  * @param array $metadata
  */
 public function deleteDocument(AMQPMessage $message)
 {
     $data = json_decode($message->body, true);
     $this->setCoreNameFromMetadata($data['metadata']);
     $updateQuery = $this->client->createUpdate();
     $updateQuery->addDeleteById(sha1($data['url']));
     $updateQuery->addCommit();
     $this->client->update($updateQuery);
 }
コード例 #10
0
 /**
  * Optimize the Solr index.
  *
  * @return bool - True on success
  */
 public function optimize()
 {
     if (!$this->_working) {
         return false;
     }
     // get an update query instance
     $update = $this->_client->createUpdate();
     $update->addOptimize();
     $solariumResult = $this->_client->update($update, 'update');
     return $this->processResult($solariumResult, 'optimize');
 }
コード例 #11
0
 public function delete($id, $core)
 {
     try {
         $this->_config['endpoint']['localhost']['path'] = '/solr/' . $core . '/';
         // create a client instance
         $client = new Client($this->_config);
         // get an update query instance
         $update = $client->createUpdate();
         // add the delete id and a commit command to the update query
         $update->addDeleteById($id);
         $update->addCommit();
         // this executes the query and returns the result
         $result = $client->update($update);
         if ($result->getStatus()) {
             throw new Exception('Invalid result returned from solr.');
         }
     } catch (Exception $e) {
         $this->_log($e);
     }
 }
コード例 #12
0
 /**
  * Exports Kloster data from mysql into solr
  *
  * @return bool
  */
 public function mysql2solrExportAction()
 {
     $this->dataImport->initializeLogger(self::exportLogFile);
     $jobOwnerFileContent = file_get_contents($this->dataImport->dumpDirectory . self::executeExportDump);
     $this->dataImport->importExportLogger->log($jobOwnerFileContent);
     $start = date('d.m.Y H:i:s');
     $date1 = new \DateTime($start);
     $this->dataImport->importExportLogger->log('Start am ' . $start);
     if (file_exists($this->dataImport->dumpDirectory . self::executeExportDump)) {
         unlink($this->dataImport->dumpDirectory . self::executeExportDump);
     }
     $klosterData = $this->klosterListAllAction();
     $klosterArr = $klosterData[0];
     $klosterstandortArr = $klosterData[1];
     $klosterordenArr = $klosterData[2];
     $standort_ordenArr = $klosterData[3];
     $update = $this->client->createUpdate();
     $docs = [];
     foreach ($klosterArr as $k => $v) {
         $doc = $update->createDocument();
         foreach ($v as $i => $v1) {
             $doc->{$i} = $v1;
         }
         array_push($docs, $doc);
     }
     foreach ($klosterstandortArr as $k => $v) {
         foreach ($v as $k1 => $v1) {
             $doc = $update->createDocument();
             foreach ($v1 as $k2 => $v2) {
                 $doc->{$k2} = $v2;
             }
             array_push($docs, $doc);
         }
     }
     foreach ($klosterordenArr as $k => $v) {
         foreach ($v as $k1 => $v1) {
             $doc = $update->createDocument();
             foreach ($v1 as $k2 => $v2) {
                 $doc->{$k2} = $v2;
             }
             array_push($docs, $doc);
         }
     }
     foreach ($standort_ordenArr as $k => $v) {
         foreach ($v as $k1 => $v1) {
             foreach ($v1 as $k2 => $v2) {
                 $doc = $update->createDocument();
                 foreach ($v2 as $k3 => $v3) {
                     $doc->{$k3} = $v3;
                 }
                 array_push($docs, $doc);
             }
         }
     }
     $update->addDocuments($docs);
     $update->addCommit();
     $this->deleteAction();
     /** @var \Solarium\Core\Query\Result\ResultInterface $result */
     $result = $this->client->execute($update);
     $logMessage = 'Data export completed in ' . round($result->getQueryTime() / 100) . ' seconds.';
     $this->logger->log($logMessage);
     $end = date('d.m.Y H:i:s');
     $date2 = new \DateTime($end);
     $this->dataImport->importExportLogger->log('Ende am ' . $end);
     $this->dataImport->importExportLogger->log('Dauer ' . $date1->diff($date2)->i . " Minuten und " . $date1->diff($date2)->s . ' Sekunden');
     return $logMessage;
 }
コード例 #13
0
 /**
  * Gets the current Solarium update query, creating one if necessary.
  *
  * @return \Solarium\QueryType\Update\Query\Query
  *   The Update query.
  */
 protected function getUpdateQuery()
 {
     if (!static::$updateQuery) {
         $this->connect();
         static::$updateQuery = $this->solr->createUpdate();
     }
     return static::$updateQuery;
 }