/** * Index all nodes by creating a new index and when everything was completed, switch the index alias. * * This command (re-)indexes all nodes contained in the content repository and sets the schema beforehand. * * @param integer $limit Amount of nodes to index at maximum * @param boolean $update if TRUE, do not throw away the index at the start. Should *only be used for development*. * @param string $workspace name of the workspace which should be indexed * @param string $postfix Index postfix, index with the same postifix will be deleted if exist * @return void */ public function buildCommand($limit = null, $update = false, $workspace = null, $postfix = null) { if ($update === true) { $this->logger->log('!!! Update Mode (Development) active!', LOG_INFO); } else { $this->nodeIndexer->setIndexNamePostfix($postfix ?: time()); if ($this->nodeIndexer->getIndex()->exists() === true) { $this->logger->log(sprintf('Deleted index with the same postfix (%s)!', $postfix), LOG_WARNING); $this->nodeIndexer->getIndex()->delete(); } $this->nodeIndexer->getIndex()->create(); $this->logger->log('Created index ' . $this->nodeIndexer->getIndexName(), LOG_INFO); $nodeTypeMappingCollection = $this->nodeTypeMappingBuilder->buildMappingInformation($this->nodeIndexer->getIndex()); foreach ($nodeTypeMappingCollection as $mapping) { /** @var \Flowpack\ElasticSearch\Domain\Model\Mapping $mapping */ $mapping->apply(); } $this->logger->log('Updated Mapping.', LOG_INFO); } $this->logger->log(sprintf('Indexing %snodes ... ', $limit !== null ? 'the first ' . $limit . ' ' : ''), LOG_INFO); $count = 0; if ($workspace === null && $this->settings['indexAllWorkspaces'] === false) { $workspace = 'live'; } $callback = function ($workspaceName, $indexedNodes, $dimensions) { if ($dimensions === []) { $this->outputLine('Workspace "' . $workspaceName . '" without dimensions done. (Indexed ' . $indexedNodes . ' nodes)'); } else { $this->outputLine('Workspace "' . $workspaceName . '" and dimensions "' . json_encode($dimensions) . '" done. (Indexed ' . $indexedNodes . ' nodes)'); } }; if ($workspace === null) { foreach ($this->workspaceRepository->findAll() as $workspace) { $count += $this->indexWorkspace($workspace->getName(), $limit, $callback); } } else { $count += $this->indexWorkspace($workspace, $limit, $callback); } $this->nodeIndexingManager->flushQueues(); $this->logger->log('Done. (indexed ' . $count . ' nodes)', LOG_INFO); $this->nodeIndexer->getIndex()->refresh(); // TODO: smoke tests if ($update === false) { $this->nodeIndexer->updateIndexAlias(); } }
/** * Index all nodes by creating a new index and when everything was completed, switch the index alias. * * This command (re-)indexes all nodes contained in the content repository and sets the schema beforehand. * * @param integer $limit Amount of nodes to index at maximum * @param boolean $update if TRUE, do not throw away the index at the start. Should *only be used for development*. * @param string $workspace name of the workspace which should be indexed * @return void */ public function buildCommand($limit = NULL, $update = FALSE, $workspace = NULL) { if ($update === TRUE) { $this->logger->log('!!! Update Mode (Development) active!', LOG_INFO); } else { $this->nodeIndexer->setIndexNamePostfix(time()); $this->nodeIndexer->getIndex()->create(); $this->logger->log('Created index ' . $this->nodeIndexer->getIndexName(), LOG_INFO); $nodeTypeMappingCollection = $this->nodeTypeMappingBuilder->buildMappingInformation($this->nodeIndexer->getIndex()); foreach ($nodeTypeMappingCollection as $mapping) { /** @var \Flowpack\ElasticSearch\Domain\Model\Mapping $mapping */ $mapping->apply(); } $this->logger->log('Updated Mapping.', LOG_INFO); } $this->logger->log(sprintf('Indexing %snodes ... ', $limit !== NULL ? 'the first ' . $limit . ' ' : ''), LOG_INFO); $count = 0; $this->limit = $limit; $this->indexedNodes = 0; $this->countedIndexedNodes = 0; if ($workspace === NULL && $this->settings['indexAllWorkspaces'] === FALSE) { $workspace = 'live'; } if ($workspace === NULL) { foreach ($this->workspaceRepository->findAll() as $workspace) { $this->indexWorkspace($workspace->getName()); $count = $count + $this->countedIndexedNodes; } } else { $this->indexWorkspace($workspace); $count = $count + $this->countedIndexedNodes; } $this->nodeIndexingManager->flushQueues(); $this->logger->log('Done. (indexed ' . $count . ' nodes)', LOG_INFO); $this->nodeIndexer->getIndex()->refresh(); // TODO: smoke tests if ($update === FALSE) { $this->nodeIndexer->updateIndexAlias(); } }