Skip to content

Commit

Permalink
TASK: Reintegrate changes from 3.0 after merge
Browse files Browse the repository at this point in the history
  • Loading branch information
daniellienert committed Feb 24, 2017
1 parent 0761c35 commit 314ecac
Show file tree
Hide file tree
Showing 10 changed files with 522 additions and 130 deletions.
84 changes: 7 additions & 77 deletions Classes/Command/NodeIndexCommandController.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,6 @@ class NodeIndexCommandController extends CommandController
*/
protected $nodeTypeMappingBuilder;

/**
* @var integer
*/
protected $limit;

/**
* @Flow\Inject
* @var \Flowpack\ElasticSearch\ContentRepositoryAdaptor\LoggerInterface
Expand Down Expand Up @@ -226,7 +221,6 @@ public function buildCommand($limit = null, $update = false, $workspace = null,
$this->logger->log(sprintf('Indexing %snodes ... ', ($limit !== null ? 'the first ' . $limit . ' ' : '')), LOG_INFO);

$count = 0;
$this->limit = $limit;

if ($workspace === null && $this->settings['indexAllWorkspaces'] === false) {
$workspace = 'live';
Expand All @@ -241,10 +235,10 @@ public function buildCommand($limit = null, $update = false, $workspace = null,
};
if ($workspace === null) {
foreach ($this->workspaceRepository->findAll() as $workspace) {
$count += $this->indexWorkspace($workspace->getName());
$count += $this->indexWorkspace($workspace->getName(), $limit, $callback);
}
} else {
$count = $this->indexWorkspace($workspace);
$count += $this->indexWorkspace($workspace, $limit, $callback);
}

$this->nodeIndexingManager->flushQueues();
Expand All @@ -266,81 +260,17 @@ public function buildCommand($limit = null, $update = false, $workspace = null,
public function cleanupCommand()
{
try {
$removedIndices = $this->nodeIndexer->removeOldIndices();
if (count($removedIndices) > 0) {
if (count($removedIndices) === 1) {
$this->logger->log('Removed old index ' . current($removedIndices) . '.');
} else {
$this->logger->log('Removed old indices ' . implode(', ', $removedIndices) . '.');
$indicesToBeRemoved = $this->nodeIndexer->removeOldIndices();
if (count($indicesToBeRemoved) > 0) {
foreach ($indicesToBeRemoved as $indexToBeRemoved) {
$this->logger->log('Removing old index ' . $indexToBeRemoved);
}
} else {
$this->logger->log('Nothing to remove.');
}
} catch (\Flowpack\ElasticSearch\Transfer\Exception\ApiException $exception) {
$response = json_decode($exception->getResponse());
$this->logger->log(sprintf('Nothing removed. ElasticSearch responded with status %s, saying "%s: %s"', $response->status, $response->error->type, $response->error->reason));
}
}

/**
* @param string $workspaceName
* @return int
*/
protected function indexWorkspace($workspaceName)
{
$indexedNodes = 0;
$combinations = $this->contentDimensionCombinator->getAllAllowedCombinations();
if ($combinations === []) {
$indexedNodes += $this->indexWorkspaceWithDimensions($workspaceName);
} else {
foreach ($combinations as $combination) {
$indexedNodes += $this->indexWorkspaceWithDimensions($workspaceName, $combination);
}
}

return $indexedNodes;
}

/**
* @param string $workspaceName
* @param array $dimensions
* @return int
*/
protected function indexWorkspaceWithDimensions($workspaceName, array $dimensions = [])
{
$indexedNodes = 0;
$context = $this->contextFactory->create(['workspaceName' => $workspaceName, 'dimensions' => $dimensions]);
$rootNode = $context->getRootNode();

$indexedNodes += $this->traverseNodes($rootNode);

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)');
}

return $indexedNodes;
}

/**
* @param NodeInterface $currentNode
* @param integer $traversedUntilNow
* @return integer Indexed nodes in this traversal
*/
protected function traverseNodes(NodeInterface $currentNode, $traversedUntilNow = 0)
{
if ($this->limit !== null && $traversedUntilNow > $this->limit) {
return $traversedUntilNow;
$this->logger->log(sprintf('Nothing removed. ElasticSearch responded with status %s, saying "%s"', $response->status, $response->error));
}

$this->nodeIndexingManager->indexNode($currentNode);
$traversedUntilNow++;

foreach ($currentNode->getChildNodes() as $childNode) {
$traversedUntilNow = $this->traverseNodes($childNode, $traversedUntilNow);
}

return $traversedUntilNow;
}
}
11 changes: 1 addition & 10 deletions Classes/Eel/ElasticSearchQueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -651,16 +651,7 @@ public function query(NodeInterface $contextNode)
// on indexing, the __parentPath is tokenized to contain ALL parent path parts,
// e.g. /foo, /foo/bar/, /foo/bar/baz; to speed up matching.. That's why we use a simple "term" filter here.
// http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-term-filter.html
$this->queryFilter('bool', [
'should' => [
[
'term' => ['__parentPath' => $contextNode->getPath()]
],
[
'term' => ['__path' => $contextNode->getPath()]
]
]
]);
$this->queryFilter('term', ['__parentPath' => $contextNode->getPath()]);

//
// http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-terms-filter.html
Expand Down
Loading

0 comments on commit 314ecac

Please sign in to comment.