Skip to content

Commit d2e0a42

Browse files
committed
🐛 Fix FullTextSearch if property is null
1 parent 42023a9 commit d2e0a42

File tree

1 file changed

+35
-2
lines changed

1 file changed

+35
-2
lines changed

src/Jackalope/Transport/DoctrineDBAL/Query/QOMWalker.php

+35-2
Original file line numberDiff line numberDiff line change
@@ -463,9 +463,19 @@ public function walkFullTextSearchConstraint(QOM\FullTextSearchInterface $constr
463463
throw new NotImplementedException('Expected full text search expression to be of type Literal, but got '.get_class($expression));
464464
}
465465

466+
if (null === $constraint->getPropertyName()) {
467+
return sprintf('%s LIKE %s',
468+
$this->sqlXpathExtractValueWithNullProperty($this->getTableAlias($constraint->getSelectorName())),
469+
$this->conn->quote('%' . $expression->getLiteralValue() . '%')
470+
);
471+
}
472+
466473
return sprintf('%s LIKE %s',
467-
$this->sqlXpathExtractValue($this->getTableAlias($constraint->getSelectorName()), $constraint->getPropertyName()),
468-
$this->conn->quote('%'.$expression->getLiteralValue().'%')
474+
$this->sqlXpathExtractValue(
475+
$this->getTableAlias($constraint->getSelectorName()),
476+
$constraint->getPropertyName()
477+
),
478+
$this->conn->quote('%' . $expression->getLiteralValue() . '%')
469479
);
470480
}
471481

@@ -841,6 +851,29 @@ private function sqlXpathExtractValue(string $alias, string $property, string $c
841851
throw new NotImplementedException(sprintf("Xpath evaluations cannot be executed with '%s' yet.", $this->platform->getName()));
842852
}
843853

854+
private function sqlXpathExtractValueWithNullProperty(string $alias): string
855+
{
856+
if ($this->platform instanceof AbstractMySQLPlatform) {
857+
return sprintf("EXTRACTVALUE(%s.props, '//sv:value')", $alias);
858+
}
859+
860+
if ($this->platform instanceof PostgreSQL94Platform || $this->platform instanceof PostgreSQLPlatform) {
861+
return sprintf(
862+
"(xpath('/sv:value/text()', CAST(%s.props AS xml), %s))[1]::text",
863+
$alias,
864+
$this->sqlXpathPostgreSQLNamespaces()
865+
);
866+
}
867+
868+
if ($this->platform instanceof SqlitePlatform) {
869+
return sprintf("EXTRACTVALUE(%s.props, '//sv:value')", $alias);
870+
}
871+
872+
throw new NotImplementedException(
873+
sprintf("Xpath evaluations cannot be executed with '%s' yet.", $this->platform->getName())
874+
);
875+
}
876+
844877
private function sqlXpathExtractNumValue(string $alias, string $property): string
845878
{
846879
if ($this->platform instanceof PostgreSQL94Platform || $this->platform instanceof PostgreSQLPlatform) {

0 commit comments

Comments
 (0)