From 8d0ad925f99792037884cafa08bfd8c7cf4cc994 Mon Sep 17 00:00:00 2001 From: Antoine Date: Mon, 2 Dec 2024 17:35:30 +0100 Subject: [PATCH] :bug: Fix FullTextSearch if property is null --- .../DoctrineDBAL/Query/QOMWalker.php | 46 ++++++++++++++++++- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/src/Jackalope/Transport/DoctrineDBAL/Query/QOMWalker.php b/src/Jackalope/Transport/DoctrineDBAL/Query/QOMWalker.php index 4f29fe28..6852cecc 100644 --- a/src/Jackalope/Transport/DoctrineDBAL/Query/QOMWalker.php +++ b/src/Jackalope/Transport/DoctrineDBAL/Query/QOMWalker.php @@ -463,9 +463,19 @@ public function walkFullTextSearchConstraint(QOM\FullTextSearchInterface $constr throw new NotImplementedException('Expected full text search expression to be of type Literal, but got '.get_class($expression)); } + if (null === $constraint->getPropertyName()) { + return sprintf('%s LIKE %s', + $this->sqlXpathExtractValueWithNullProperty($this->getTableAlias($constraint->getSelectorName())), + $this->conn->quote('%' . $expression->getLiteralValue() . '%') + ); + } + return sprintf('%s LIKE %s', - $this->sqlXpathExtractValue($this->getTableAlias($constraint->getSelectorName()), $constraint->getPropertyName()), - $this->conn->quote('%'.$expression->getLiteralValue().'%') + $this->sqlXpathExtractValue( + $this->getTableAlias($constraint->getSelectorName()), + $constraint->getPropertyName() + ), + $this->conn->quote('%' . $expression->getLiteralValue() . '%') ); } @@ -841,6 +851,38 @@ private function sqlXpathExtractValue(string $alias, string $property, string $c throw new NotImplementedException(sprintf("Xpath evaluations cannot be executed with '%s' yet.", $this->platform->getName())); } + private function sqlXpathExtractValueWithNullProperty(string $alias, string $column = 'props'): string + { + if ($this->platform instanceof AbstractMySQLPlatform) { + return sprintf( + "EXTRACTVALUE(%s.%s, '//sv:value')", + $alias, + $column + ); + } + + if ($this->platform instanceof PostgreSQL94Platform || $this->platform instanceof PostgreSQLPlatform) { + return sprintf( + "(xpath('/sv:value/text()', CAST(%s.%s AS xml), %s))[1]::text", + $alias, + $column, + $this->sqlXpathPostgreSQLNamespaces() + ); + } + + if ($this->platform instanceof SqlitePlatform) { + return sprintf( + "EXTRACTVALUE(%s.%s, '//sv:value')", + $alias, + $column + ); + } + + throw new NotImplementedException( + sprintf("Xpath evaluations cannot be executed with '%s' yet.", $this->platform->getName()) + ); + } + private function sqlXpathExtractNumValue(string $alias, string $property): string { if ($this->platform instanceof PostgreSQL94Platform || $this->platform instanceof PostgreSQLPlatform) {