Skip to content

Commit

Permalink
🐛 Fix FullTextSearch if property is null
Browse files Browse the repository at this point in the history
  • Loading branch information
elyanory committed Dec 12, 2024
1 parent 42023a9 commit d2e0a42
Showing 1 changed file with 35 additions and 2 deletions.
37 changes: 35 additions & 2 deletions src/Jackalope/Transport/DoctrineDBAL/Query/QOMWalker.php
Original file line number Diff line number Diff line change
Expand Up @@ -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() . '%')
);
}

Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit d2e0a42

Please sign in to comment.