From d2e0a42af1c6cf247821150ca19edc16d08e0c8c 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 | 37 ++++++++++++++++++- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/src/Jackalope/Transport/DoctrineDBAL/Query/QOMWalker.php b/src/Jackalope/Transport/DoctrineDBAL/Query/QOMWalker.php index 4f29fe28..4a7e23ae 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,29 @@ 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 + { + if ($this->platform instanceof AbstractMySQLPlatform) { + return sprintf("EXTRACTVALUE(%s.props, '//sv:value')", $alias); + } + + if ($this->platform instanceof PostgreSQL94Platform || $this->platform instanceof PostgreSQLPlatform) { + return sprintf( + "(xpath('/sv:value/text()', CAST(%s.props AS xml), %s))[1]::text", + $alias, + $this->sqlXpathPostgreSQLNamespaces() + ); + } + + if ($this->platform instanceof SqlitePlatform) { + return sprintf("EXTRACTVALUE(%s.props, '//sv:value')", $alias); + } + + 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) {