Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FEATURE: Add flag for only indexing the live workspace #47

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Classes/AssetExtraction/NullAssetExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@

class NullAssetExtractor implements AssetExtractorInterface
{
/**
* @throws NotImplementedException
*/
public function extract(AssetInterface $asset): AssetContent
{
throw new NotImplementedException('AssetExtractor is not implemented in SimpleSearchAdaptor.');
}
}
}
15 changes: 10 additions & 5 deletions Classes/Command/NodeIndexCommandController.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,25 @@ class NodeIndexCommandController extends CommandController
*/
protected $indexedNodes;

/**
* @var array
* @Flow\InjectConfiguration(package="Neos.ContentRepository.Search")
*/
protected $settings;

/**
* Index all nodes.
*
* This command (re-)indexes all nodes contained in the content repository and sets the schema beforehand.
*
*
* @param string $workspace
* @return void
* @throws Exception
*/
public function buildCommand(string $workspace = null): void
{
if ($workspace === null && $this->settings['indexAllWorkspaces'] === false) {
$workspace = 'live';
}

$this->indexedNodes = 0;
if ($workspace === null) {
foreach ($this->workspaceRepository->findAll() as $workspaceInstance) {
Expand All @@ -89,7 +96,6 @@ public function buildCommand(string $workspace = null): void
}

/**
* @param string $workspaceName
* @throws Exception
*/
protected function indexWorkspace(string $workspaceName): void
Expand All @@ -116,7 +122,6 @@ protected function indexWorkspace(string $workspaceName): void
}

/**
* @param NodeInterface $currentNode
* @throws Exception
*/
protected function traverseNodes(NodeInterface $currentNode): void
Expand Down
65 changes: 25 additions & 40 deletions Classes/Indexer/NodeIndexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@
use Neos\ContentRepository\Exception\NodeException;
use Neos\ContentRepository\Search\Exception\IndexingException;
use Neos\ContentRepository\Search\Indexer\AbstractNodeIndexer;
use Neos\ContentRepository\Search\Search\QueryBuilderInterface;
use Neos\Eel\Exception;
use Neos\Flow\Annotations as Flow;
use Neos\Flow\Configuration\Exception\InvalidConfigurationTypeException;
use Neos\Flow\Persistence\PersistenceManagerInterface;
use Neos\Flow\Security\Context;
use Symfony\Component\Yaml\Yaml;
Expand All @@ -33,7 +35,7 @@ class NodeIndexer extends AbstractNodeIndexer

/**
* @Flow\Inject
* @var \Neos\ContentRepository\Search\Search\QueryBuilderInterface
* @var QueryBuilderInterface
*/
protected $queryBuilder;

Expand Down Expand Up @@ -67,6 +69,12 @@ class NodeIndexer extends AbstractNodeIndexer
*/
protected $contextFactory;

/**
* @var array
* @Flow\InjectConfiguration(package="Neos.ContentRepository.Search")
*/
protected $settings;

/**
* @Flow\Inject
* @var Context
Expand All @@ -87,9 +95,9 @@ class NodeIndexer extends AbstractNodeIndexer
* Called by the Flow object framework after creating the object and resolving all dependencies.
*
* @param integer $cause Creation cause
* @throws \Neos\Flow\Configuration\Exception\InvalidConfigurationTypeException
* @throws InvalidConfigurationTypeException
*/
public function initializeObject($cause)
public function initializeObject($cause): void
{
parent::initializeObject($cause);
foreach ($this->nodeTypeManager->getNodeTypes() as $nodeType) {
Expand All @@ -100,9 +108,6 @@ public function initializeObject($cause)
}
}

/**
* @return IndexInterface
*/
public function getIndexClient(): IndexInterface
{
return $this->indexClient;
Expand All @@ -111,16 +116,25 @@ public function getIndexClient(): IndexInterface
/**
* index this node, and add it to the current bulk request.
*
* @param NodeInterface $node
* @param string $targetWorkspaceName
* @param boolean $indexVariants
* @return void
* @throws NodeException
* @throws IndexingException
* @throws Exception
* @throws NodeException|IndexingException|Exception
*/
public function indexNode(NodeInterface $node, $targetWorkspaceName = null, $indexVariants = true): void
{
if ($this->settings['indexAllWorkspaces'] === false) {
// we are only supposed to index the live workspace.
// We need to check the workspace at two occasions; checking the
// $targetWorkspaceName and the workspace name of the node's context as fallback
if ($targetWorkspaceName !== null && $targetWorkspaceName !== 'live') {
return;
}

if ($targetWorkspaceName === null && $node->getContext()->getWorkspaceName() !== 'live') {
return;
}
}

if ($indexVariants === true) {
$this->indexAllNodeVariants($node);
return;
Expand Down Expand Up @@ -157,27 +171,18 @@ public function indexNode(NodeInterface $node, $targetWorkspaceName = null, $ind
}
}

/**
* @param NodeInterface $node
* @return void
*/
public function removeNode(NodeInterface $node): void
{
$identifier = $this->generateUniqueNodeIdentifier($node);
$this->indexClient->removeData($identifier);
}

/**
* @return void
*/
public function flush(): void
{
$this->indexedNodeData = [];
}

/**
* @param NodeInterface $node
* @return void
* @throws \Exception
*/
protected function indexAllNodeVariants(NodeInterface $node): void
Expand All @@ -198,8 +203,6 @@ protected function indexAllNodeVariants(NodeInterface $node): void
}

/**
* @param string $nodeIdentifier
* @param string $workspaceName
* @throws \Exception
*/
protected function indexNodeInWorkspace(string $nodeIdentifier, string $workspaceName): void
Expand All @@ -225,10 +228,6 @@ protected function indexNodeInWorkspace(string $nodeIdentifier, string $workspac
});
}

/**
* @param NodeInterface $node
* @param array $fulltext
*/
protected function addFulltextToRoot(NodeInterface $node, array $fulltext): void
{
$fulltextRoot = $this->findFulltextRoot($node);
Expand All @@ -238,10 +237,6 @@ protected function addFulltextToRoot(NodeInterface $node, array $fulltext): void
}
}

/**
* @param NodeInterface $node
* @return NodeInterface
*/
protected function findFulltextRoot(NodeInterface $node): ?NodeInterface
{
if (in_array($node->getNodeType()->getName(), $this->fulltextRootNodeTypes, true)) {
Expand All @@ -266,19 +261,12 @@ protected function findFulltextRoot(NodeInterface $node): ?NodeInterface

/**
* Generate identifier for index entry based on node identifier and context
*
* @param NodeInterface $node
* @return string
*/
protected function generateUniqueNodeIdentifier(NodeInterface $node): string
{
return $this->persistenceManager->getIdentifierByObject($node->getNodeData());
}

/**
* @param array $nodePropertiesToBeStoredInIndex
* @return array
*/
protected function postProcess(array $nodePropertiesToBeStoredInIndex): array
{
foreach ($nodePropertiesToBeStoredInIndex as $propertyName => $propertyValue) {
Expand All @@ -290,9 +278,6 @@ protected function postProcess(array $nodePropertiesToBeStoredInIndex): array
return $nodePropertiesToBeStoredInIndex;
}

/**
* @return array
*/
public function calculateDimensionCombinations(): array
{
$dimensionPresets = $this->contentDimensionPresetSource->getAllPresets();
Expand Down
50 changes: 7 additions & 43 deletions Classes/Search/AbstractQueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ public function fulltext(string $searchWord, array $options = []): QueryBuilderI
}

/**
* @param NodeInterface $contextNode
* @return MysqlQueryBuilder
* @throws IllegalObjectTypeException
*/
Expand All @@ -90,21 +89,14 @@ public function query(NodeInterface $contextNode): QueryBuilderInterface
return $this;
}

/**
* @param string $nodeIdentifierPlaceholder
* @return string
*/
abstract public function getFindIdentifiersByNodeIdentifierQuery(string $nodeIdentifierPlaceholder);
abstract public function getFindIdentifiersByNodeIdentifierQuery(string $nodeIdentifierPlaceholder): string;

/**
* HIGH-LEVEL API
*/

/**
* Filter by node type, taking inheritance into account.
*
* @param string $nodeType the node type to filter for
* @return QueryBuilderInterface
*/
public function nodeType(string $nodeType): QueryBuilderInterface
{
Expand All @@ -115,10 +107,6 @@ public function nodeType(string $nodeType): QueryBuilderInterface

/**
* add an exact-match query for a given property
*
* @param string $propertyName
* @param mixed $propertyValue
* @return QueryBuilderInterface
*/
public function exactMatch(string $propertyName, $propertyValue): QueryBuilderInterface
{
Expand All @@ -132,10 +120,6 @@ public function exactMatch(string $propertyName, $propertyValue): QueryBuilderIn

/**
* add an like query for a given property
*
* @param string $propertyName
* @param mixed $propertyValue
* @return QueryBuilderInterface
*/
public function like(string $propertyName, $propertyValue): QueryBuilderInterface
{
Expand All @@ -149,12 +133,8 @@ public function like(string $propertyName, $propertyValue): QueryBuilderInterfac

/**
* add a greater than query for a given property
*
* @param string $propertyName
* @param mixed $propertyValue
* @return QueryBuilderInterface
*/
public function greaterThan($propertyName, $propertyValue)
public function greaterThan($propertyName, $propertyValue): QueryBuilderInterface
{
if ($propertyValue instanceof NodeInterface) {
$propertyValue = (string) $propertyValue->getNodeAggregateIdentifier();
Expand All @@ -166,12 +146,8 @@ public function greaterThan($propertyName, $propertyValue)

/**
* add a greater than or equal query for a given property
*
* @param string $propertyName
* @param mixed $propertyValue
* @return QueryBuilderInterface
*/
public function greaterThanOrEqual($propertyName, $propertyValue)
public function greaterThanOrEqual(string $propertyName, $propertyValue): QueryBuilderInterface
{
if ($propertyValue instanceof NodeInterface) {
$propertyValue = (string) $propertyValue->getNodeAggregateIdentifier();
Expand All @@ -183,12 +159,8 @@ public function greaterThanOrEqual($propertyName, $propertyValue)

/**
* add a less than query for a given property
*
* @param string $propertyName
* @param mixed $propertyValue
* @return QueryBuilderInterface
*/
public function lessThan($propertyName, $propertyValue)
public function lessThan(string $propertyName, $propertyValue): QueryBuilderInterface
{
if ($propertyValue instanceof NodeInterface) {
$propertyValue = (string) $propertyValue->getNodeAggregateIdentifier();
Expand All @@ -200,12 +172,8 @@ public function lessThan($propertyName, $propertyValue)

/**
* add a less than query for a given property
*
* @param string $propertyName
* @param mixed $propertyValue
* @return QueryBuilderInterface
*/
public function lessThanOrEqual($propertyName, $propertyValue)
public function lessThanOrEqual(string $propertyName, $propertyValue): QueryBuilderInterface
{
if ($propertyValue instanceof NodeInterface) {
$propertyValue = (string) $propertyValue->getNodeAggregateIdentifier();
Expand Down Expand Up @@ -249,9 +217,8 @@ public function execute(): \Traversable
* Log the current request for debugging after it has been executed.
*
* @param string $message an optional message to identify the log entry
* @return AbstractQueryBuilder
*/
public function log($message = null)
public function log(string $message = null): AbstractQueryBuilder
{
$this->queryLogEnabled = true;
$this->logMessage = $message;
Expand All @@ -261,8 +228,6 @@ public function log($message = null)

/**
* Return the total number of hits for the query.
*
* @return integer
*/
public function count(): int
{
Expand All @@ -279,9 +244,8 @@ public function count(): int

/**
* @param string $methodName
* @return boolean
*/
public function allowsCallOfMethod($methodName)
public function allowsCallOfMethod($methodName): bool
{
if ($methodName !== 'getFindIdentifiersByNodeIdentifierQuery') {
// query must be called first to establish a context and starting point.
Expand Down
6 changes: 1 addition & 5 deletions Classes/Search/MysqlQueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,12 @@ protected function getSimpleSearchQueryBuilder(): QueryBuilderInterface
return $this->mysqlQueryBuilder;
}

/**
* @param string $nodeIdentifierPlaceholder
* @return string
*/
public function getFindIdentifiersByNodeIdentifierQuery(string $nodeIdentifierPlaceholder): string
{
return 'SELECT "__identifier__" FROM "fulltext_objects" WHERE "__identifier" = :' . $nodeIdentifierPlaceholder;
}

public function fulltextMatchResult($searchword, $resultTokens = 200, $ellipsis = '...', $beginModifier = '<b>', $endModifier = '</b>'): string
public function fulltextMatchResult(string $searchword, int $resultTokens = 200, string $ellipsis = '...', string $beginModifier = '<b>', string $endModifier = '</b>'): string
{
return $this->mysqlQueryBuilder->fulltextMatchResult($searchword, $resultTokens, $ellipsis, $beginModifier, $endModifier);
}
Expand Down
Loading