/** * Returns a like criterion used for matching objects against a query. * Matches if the property named $propertyName is like the $operand, using * standard SQL wildcards. * * @param string $propertyName The name of the property to compare against * @param string $operand The value to compare with * @param boolean $caseSensitive Whether the matching should be done case-sensitive * @return object * @throws InvalidQueryException if used on a non-string property * @api */ public function like($propertyName, $operand, $caseSensitive = true) { $aliasedPropertyName = $this->getPropertyNameWithAlias($propertyName); if ($caseSensitive === true) { return $this->queryBuilder->expr()->like($aliasedPropertyName, $this->getParamNeedle($operand)); } return $this->queryBuilder->expr()->like($this->queryBuilder->expr()->lower($aliasedPropertyName), $this->getParamNeedle(UnicodeFunctions::strtolower($operand))); }
/** * Find nodes by a value in properties * * This method is internal and will be replaced with better search capabilities. * * @param string|array $term Search term * @param string $nodeTypeFilter Node type filter * @param Workspace $workspace * @param array $dimensions * @param string $pathStartingPoint * @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; }
/** * Checks if our version of strtolower can at least handle some common special chars * * @test */ public function strtolowerWorksWithCertainSpecialChars() { $testString = 'HERE ARE SOME CHARACTERS: ÄÖÜÄÖÜßÉÈÊÅÅØØÆÆŒŒ ...'; $expectedResult = 'here are some characters: äöüäöüßéèêååøøæ朜 ...'; $result = Functions::strtolower($testString); $this->assertEquals($expectedResult, $result, 'strtolower() could not convert our selection of special characters.'); }