Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Fix FullTextSearch if property is null #452

Open
wants to merge 1 commit into
base: 2.x
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading