Skip to content

Commit

Permalink
WIP TASK: Reimplement NodeSearchService based on findDescendantNodes
Browse files Browse the repository at this point in the history
  • Loading branch information
mhsdesign committed Sep 23, 2023
1 parent fee1867 commit 6d67d46
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 25 deletions.
1 change: 1 addition & 0 deletions Neos.Neos/Classes/Controller/Service/NodesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ public function indexAction(
$entryNode = $subgraph->findNodeByAbsolutePath($nodePath);
}

// TODO use `NodeSearchService` again
$nodes = !is_null($entryNode) ? $subgraph->findDescendantNodes(
$entryNode->nodeAggregateId,
FindDescendantNodesFilter::create(
Expand Down
55 changes: 35 additions & 20 deletions Neos.Neos/Classes/Domain/Service/NodeSearchService.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,44 @@

namespace Neos\Neos\Domain\Service;

use Neos\ContentRepository\Core\Projection\ContentGraph\AbsoluteNodePath;
use Neos\ContentRepository\Core\Projection\ContentGraph\ContentSubgraphInterface;
use Neos\ContentRepository\Core\Projection\ContentGraph\Filter\FindDescendantNodesFilter;
use Neos\ContentRepository\Core\Projection\ContentGraph\Node;
use Neos\Flow\Annotations as Flow;
use Neos\ContentRepository\Core\Projection\ContentGraph\Nodes;
use Neos\ContentRepository\Core\Projection\ContentGraph\NodeTypeConstraints;
use Neos\ContentRepository\Core\Projection\ContentGraph\SearchTerm;

/**
* Implementation of the NodeSearchServiceInterface for greater backwards compatibility
*
* Note: This implementation is meant to ease the transition to an event sourced content repository
* but since it uses legacy classes (like \Neos\ContentRepository\Domain\Service\Context) it is
* advised to use ContentSubgraphInterface::findDescendantNodes() directly instead.
*
* @Flow\Scope("singleton")
* @deprecated see above
*/
class NodeSearchService implements NodeSearchServiceInterface
{
/**
* @param array<int,string> $searchNodeTypes
*/
public function findByProperties(
string $term,
array $searchNodeTypes,
?Node $startingPoint = null
): never {
throw new \InvalidArgumentException('Cannot find nodes with the current set of arguments', 1651923867);
private function __construct(
private readonly ContentSubgraphInterface $subgraph
) {
}

public function create(ContentSubgraphInterface $subgraph): self
{
return new self($subgraph);
}

public function findNodes(
Node|AbsoluteNodePath $entry,
SearchTerm $searchTerm,
NodeTypeConstraints $nodeTypeConstraints
): Nodes {
if ($entry instanceof AbsoluteNodePath) {
$entryNode = $this->subgraph->findNodeByAbsolutePath($entry);
} else {
$entryNode = $entry;
}

return $this->subgraph->findDescendantNodes(
$entryNode->nodeAggregateId,
FindDescendantNodesFilter::create(
nodeTypeConstraints: $nodeTypeConstraints,
searchTerm: $searchTerm,
)
);
}
}

15 changes: 10 additions & 5 deletions Neos.Neos/Classes/Domain/Service/NodeSearchServiceInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,20 @@

namespace Neos\Neos\Domain\Service;

use Neos\ContentRepository\Core\Projection\ContentGraph\AbsoluteNodePath;
use Neos\ContentRepository\Core\Projection\ContentGraph\Node;
use Neos\ContentRepository\Core\Projection\ContentGraph\Nodes;
use Neos\ContentRepository\Core\Projection\ContentGraph\NodeTypeConstraints;
use Neos\ContentRepository\Core\Projection\ContentGraph\SearchTerm;

/**
* Interface for the node search service for finding nodes based on a fulltext search
* Interface for the node search service for finding nodes (based on a fulltext search)
*/
interface NodeSearchServiceInterface
{
/**
* @param array<int,string> $searchNodeTypes
*/
public function findByProperties(string $term, array $searchNodeTypes): Nodes;
public function findNodes(
Node|AbsoluteNodePath $entry,
SearchTerm $searchTerm,
NodeTypeConstraints $nodeTypeConstraints
): Nodes;
}

0 comments on commit 6d67d46

Please sign in to comment.