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 2, 2024
1 parent 42023a9 commit 8d0ad92
Showing 1 changed file with 44 additions and 2 deletions.
46 changes: 44 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,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) {
Expand Down

0 comments on commit 8d0ad92

Please sign in to comment.