Neos\ContentRepository\Domain\Repository\NodeDataRepository::findByProperties PHP Method

findByProperties() public method

This method is internal and will be replaced with better search capabilities.
public findByProperties ( string | array $term, string $nodeTypeFilter, Workspace $workspace, array $dimensions, string $pathStartingPoint = null ) : array<\Neos\ContentRepository\Domain\Model\NodeData>
$term string | array Search term
$nodeTypeFilter string Node type filter
$workspace Neos\ContentRepository\Domain\Model\Workspace
$dimensions array
$pathStartingPoint string
return array<\Neos\ContentRepository\Domain\Model\NodeData>
    public function findByProperties($term, $nodeTypeFilter, $workspace, $dimensions, $pathStartingPoint = null)
    {
        if (empty($term)) {
            throw new \InvalidArgumentException('"term" cannot be empty: provide a term to search for.', 1421329285);
        }
        $workspaces = $this->collectWorkspaceAndAllBaseWorkspaces($workspace);
        $queryBuilder = $this->createQueryBuilder($workspaces);
        $this->addDimensionJoinConstraintsToQueryBuilder($queryBuilder, $dimensions);
        $this->addNodeTypeFilterConstraintsToQueryBuilder($queryBuilder, $nodeTypeFilter);
        if (is_array($term)) {
            if (count($term) !== 1) {
                throw new \InvalidArgumentException('Currently only a 1-dimensional key => value array term is supported.', 1460437584);
            }
            // Build the like parameter as "key": "value" to search by a specific key and value
            $likeParameter = '%' . UnicodeFunctions::strtolower(trim(json_encode($term, JSON_PRETTY_PRINT | JSON_FORCE_OBJECT | JSON_UNESCAPED_UNICODE), "{}\n\t ")) . '%';
        } else {
            // Convert to lowercase, then to json, and then trim quotes from json to have valid JSON escaping.
            $likeParameter = '%' . trim(json_encode(UnicodeFunctions::strtolower($term), JSON_UNESCAPED_UNICODE), '"') . '%';
        }
        $queryBuilder->andWhere("LOWER(NEOSCR_TOSTRING(n.properties)) LIKE :term")->setParameter('term', $likeParameter);
        if (strlen($pathStartingPoint) > 0) {
            $pathStartingPoint = strtolower($pathStartingPoint);
            $queryBuilder->andWhere($queryBuilder->expr()->orx()->add($queryBuilder->expr()->eq('n.parentPathHash', ':parentPathHash'))->add($queryBuilder->expr()->eq('n.pathHash', ':pathHash'))->add($queryBuilder->expr()->like('n.parentPath', ':parentPath')))->setParameter('parentPathHash', md5($pathStartingPoint))->setParameter('pathHash', md5($pathStartingPoint))->setParameter('parentPath', rtrim($pathStartingPoint, '/') . '/%');
        }
        $query = $queryBuilder->getQuery();
        $foundNodes = $query->getResult();
        $foundNodes = $this->reduceNodeVariantsByWorkspacesAndDimensions($foundNodes, $workspaces, $dimensions);
        $foundNodes = $this->filterRemovedNodes($foundNodes, false);
        return $foundNodes;
    }

Usage Example

 /**
  * Search all properties for given $term
  *
  * TODO: Implement a better search when Flow offer the possibility
  *
  * @param string|array $term search term
  * @param array $searchNodeTypes
  * @param Context $context
  * @param NodeInterface $startingPoint
  * @return array <\Neos\ContentRepository\Domain\Model\NodeInterface>
  */
 public function findByProperties($term, array $searchNodeTypes, Context $context, NodeInterface $startingPoint = null)
 {
     if (empty($term)) {
         throw new \InvalidArgumentException('"term" cannot be empty: provide a term to search for.', 1421329285);
     }
     $searchResult = array();
     $nodeTypeFilter = implode(',', $searchNodeTypes);
     $nodeDataRecords = $this->nodeDataRepository->findByProperties($term, $nodeTypeFilter, $context->getWorkspace(), $context->getDimensions(), $startingPoint ? $startingPoint->getPath() : null);
     foreach ($nodeDataRecords as $nodeData) {
         $node = $this->nodeFactory->createFromNodeData($nodeData, $context);
         if ($node !== null) {
             $searchResult[$node->getPath()] = $node;
         }
     }
     return $searchResult;
 }
All Usage Examples Of Neos\ContentRepository\Domain\Repository\NodeDataRepository::findByProperties