Skip to content

Commit

Permalink
Add Doctrine support for not like searches
Browse files Browse the repository at this point in the history
  • Loading branch information
davidwindell authored Jan 28, 2019
1 parent deb92c5 commit 8ba9c7d
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/Edge/Doctrine/Search/DoctrineSearcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,8 @@ protected function getExpression($field, $operator, &$value, $param, $type = nul
return $this->getNotEqualsExpr($field, $value, $param);
case Filter::COMPARISON_LIKE:
return $this->getLikeExpr($field, $value, $param, $type);
case Filter::COMPARISON_NOT_LIKE:
return $this->getNotLikeExpr($field, $value, $param, $type);
case Filter::COMPARISON_GREATER:
return $this->getGreaterThanExpr($field, $param);
case Filter::COMPARISON_GREATER_OR_EQ:
Expand Down Expand Up @@ -376,6 +378,24 @@ protected function getLikeExpr($field, &$value, $paramName, $type = null)
return $this->getQueryBuilder()->expr()->like($field, $paramName);
}

/**
* Get a not like expression for specified field and data
*
* @param string $field field name
* @param mixed $value search value
* @param string $paramName parameter name to use
*/
protected function getNotLikeExpr($field, &$value, $paramName, $type = null)
{
if (null === $value || $type == self::FIELD_TYPE_INTEGER) {
return $this->getNotEqualsExpr($field, $value, $paramName);
}

$value = '%' . $value . '%';

return $this->getQueryBuilder()->expr()->notLike($field, $paramName);
}

protected function getGreaterThanExpr($field, $paramName)
{
return $this->getQueryBuilder()->expr()->gt($field, $paramName);
Expand Down

0 comments on commit 8ba9c7d

Please sign in to comment.