Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mficzel/292d6dab09ea0ef9017b804ad49f97a2 to your computer and use it in GitHub Desktop.
Save mficzel/292d6dab09ea0ef9017b804ad49f97a2 to your computer and use it in GitHub Desktop.
Remove items from search result that are not connected to root because of hidden parents
<?php
namespace Vendor\Site\Aspects;
use Neos\ContentRepository\Domain\Model\NodeInterface;
use Neos\Flow\Annotations as Flow;
use Neos\Flow\Aop\JoinPointInterface;
/**
* @Flow\Aspect
*/
class RemoveNodesWithHiddenParentsFromSearchResults
{
/**
* Remove nodes that have no connection to root
*
* @Flow\Around("method(Flowpack\ElasticSearch\ContentRepositoryAdaptor\Eel\ElasticSearchQueryBuilder->convertHitsToNodes())")
*
* @param JoinPointInterface $joinPoint
* @return array
*/
public function filterNodesThatAreNotConncetedToRoot(JoinPointInterface $joinPoint)
{
$result = $joinPoint->getAdviceChain()->proceed($joinPoint);
return array_filter(
$result,
function(NodeInterface $node) {
while ($node = $node->getParent()) {
if (!$node) {
return false;
} elseif ($node->getPath() == '/sites') {
return true;
}
}
return false;
}
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment