/** * {@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())); }
/** * 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(); }
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(); }
/** * Gets summary information about the Solr Core. * * @return array */ public function getStatsSummary() { $summary = array('@pending_docs' => '', '@autocommit_time_seconds' => '', '@autocommit_time' => '', '@deletes_by_id' => '', '@deletes_by_query' => '', '@deletes_total' => '', '@schema_version' => '', '@core_name' => '', '@index_size' => ''); $solr_version = $this->getSolrVersion(); $query = $this->solr->createPing(); $query->setResponseWriter(Query::WT_PHPS); if (version_compare($solr_version, '4', '>=')) { $query->setHandler('admin/mbeans?stats=true'); } else { $query->setHandler('admin/stats.jsp'); } $stats = $this->solr->execute($query)->getData(); if (!empty($stats)) { if (version_compare($solr_version, '3', '<=')) { // @todo Needs to be updated by someone who has a Solr 3.x setup. /* $docs_pending_xpath = $stats->xpath('//stat[@name="docsPending"]'); $summary['@pending_docs'] = (int) trim(current($docs_pending_xpath)); $max_time_xpath = $stats->xpath('//stat[@name="autocommit maxTime"]'); $max_time = (int) trim(current($max_time_xpath)); // Convert to seconds. $summary['@autocommit_time_seconds'] = $max_time / 1000; $summary['@autocommit_time'] = \Drupal::service('date')->formatInterval($max_time / 1000); $deletes_id_xpath = $stats->xpath('//stat[@name="deletesById"]'); $summary['@deletes_by_id'] = (int) trim(current($deletes_id_xpath)); $deletes_query_xpath = $stats->xpath('//stat[@name="deletesByQuery"]'); $summary['@deletes_by_query'] = (int) trim(current($deletes_query_xpath)); $summary['@deletes_total'] = $summary['@deletes_by_id'] + $summary['@deletes_by_query']; $schema = $stats->xpath('/solr/schema[1]'); $summary['@schema_version'] = trim($schema[0]); $core = $stats->xpath('/solr/core[1]'); $summary['@core_name'] = trim($core[0]); $size_xpath = $stats->xpath('//stat[@name="indexSize"]'); $summary['@index_size'] = trim(current($size_xpath)); */ } else { $update_handler_stats = $stats['solr-mbeans']['UPDATEHANDLER']['updateHandler']['stats']; $summary['@pending_docs'] = (int) $update_handler_stats['docsPending']; $max_time = (int) $update_handler_stats['autocommit maxTime']; // Convert to seconds. $summary['@autocommit_time_seconds'] = $max_time / 1000; $summary['@autocommit_time'] = \Drupal::service('date.formatter')->formatInterval($max_time / 1000); $summary['@deletes_by_id'] = (int) $update_handler_stats['deletesById']; $summary['@deletes_by_query'] = (int) $update_handler_stats['deletesByQuery']; $summary['@deletes_total'] = $summary['@deletes_by_id'] + $summary['@deletes_by_query']; $summary['@schema_version'] = $this->getSystemInfo()['core']['schema']; $summary['@core_name'] = $stats['solr-mbeans']['CORE']['core']['stats']['coreName']; $summary['@index_size'] = $stats['solr-mbeans']['QUERYHANDLER']['/replication']['stats']['indexSize']; } } return $summary; }
/** * Main starting point for blank index action * @return array */ public function getDefaultQuery() { $this->createQueryForArguments($this->getRequestArguments()); $error = null; $resultSet = null; try { $resultSet = $this->connection->execute($this->query); } catch (HttpException $exception) { LoggerUtility::logError('find: Solr Exception (Timeout?)', ['requestArguments' => $this->getRequestArguments(), 'exception' => LoggerUtility::exceptionToArray($exception)]); $error = ['solr' => $exception]; } return ['results' => $resultSet, 'error' => $error]; }
/** * 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; }
/** * Retrieves a config file or file list from the Solr server. * * Uses the admin/file request handler. * * @param string|null $file * (optional) The name of the file to retrieve. If the file is a directory, * the directory contents are instead listed and returned. NULL represents * the root config directory. * * @return \Solarium\Core\Client\Response * A Solarium response object containing either the file contents or a file * list. */ public function getFile($file = NULL) { $this->connect(); $query = $this->solr->createPing(); $query->setHandler('admin/file'); $query->addParam('contentType', 'text/xml;charset=utf-8'); if ($file) { $query->addParam('file', $file); } return $this->solr->execute($query)->getResponse(); }