Skip to content

Commit

Permalink
Merge branch 'master' into gerhard-boden-namepache-change
Browse files Browse the repository at this point in the history
  • Loading branch information
kitsunet committed Feb 14, 2017
2 parents c5e2b33 + 388312e commit d5f7414
Showing 1 changed file with 122 additions and 0 deletions.
122 changes: 122 additions & 0 deletions Classes/Search/SqLiteQueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,128 @@ public function fulltextMatchResult($searchword, $resultTokens = 60, $ellipsis =
return '';
}

/**
* Match any value in the given array for the property
*
* @param string $propertyName
* @param array $propertyValues
* @return QueryBuilder
*/
public function anyMatch($propertyName, $propertyValues) {
if ($propertyValues === null || empty($propertyValues) || $propertyValues[0] === null) {
return $this;
}

$queryString = null;
$lastElemtentKey = count($propertyValues) - 1;
foreach($propertyValues as $key => $propertyValue) {
$parameterName = ':' . md5($propertyName . '#' . count($this->where) . $key);
$this->parameterMap[$parameterName] = $propertyValue;

if ($key === 0) {
$queryString .= '(';
}
if ($key !== $lastElemtentKey) {
$queryString .= sprintf("(`%s`) = %s OR ", $propertyName, $parameterName);
} else {
$queryString .= sprintf("(`%s`) = %s )", $propertyName, $parameterName);
}
}

$this->where[] = $queryString;

return $this;
}

/**
* Match any value which is like in the given array for the property
*
* @param string $propertyName
* @param array $propertyValues
* @return QueryBuilder
*/
public function likeAnyMatch($propertyName, $propertyValues) {
if ($propertyValues === null || empty($propertyValues) || $propertyValues[0] === null) {
return $this;
}

$queryString = null;
$lastElemtentKey = count($propertyValues) - 1;
foreach($propertyValues as $key => $propertyValue) {
$parameterName = ':' . md5($propertyName . '#' . count($this->where) . $key);
$this->parameterMap[$parameterName] = '%'.$propertyValue.'%';

if ($key === 0) {
$queryString .= '(';
}
if ($key !== $lastElemtentKey) {
$queryString .= sprintf("(`%s`) LIKE %s OR ", $propertyName, $parameterName);
} else {
$queryString .= sprintf("(`%s`) LIKE %s)", $propertyName, $parameterName);
}
}

$this->where[] = $queryString;

return $this;
}

/**
* Add a range filter (gt) for the given property
*
* @param string $propertyName Name of the property
* @param mixed $value Value for comparison
* @return QueryBuilder
* @api
*/
public function greaterThan($propertyName, $value) {
$this->where[] = sprintf(" (`%s`) > %s", $propertyName, $value);

return $this;
}

/**
* Add a range filter (lt) for the given property
*
* @param string $propertyName Name of the property
* @param mixed $value Value for comparison
* @return QueryBuilder
* @api
*/
public function lessThan($propertyName, $value) {
$this->where[] = sprintf(" (`%s`) < %s", $propertyName, $value);

return $this;
}

/**
* Add a range filter (gte) for the given property
*
* @param string $propertyName Name of the property
* @param mixed $value Value for comparison
* @return QueryBuilder
* @api
*/
public function greaterThanOrEqual($propertyName, $value) {
$this->where[] = sprintf(" (`%s`) >= %s", $propertyName, $value);

return $this;
}

/**
* Add a range filter (lte) for the given property
*
* @param string $propertyName Name of the property
* @param mixed $value Value for comparison
* @return QueryBuilder
* @api
*/
public function lessThanOrEqual($propertyName, $value) {
$this->where[] = sprintf(" (`%s`) <= %s", $propertyName, $value);

return $this;
}

/**
* @return string
*/
Expand Down

0 comments on commit d5f7414

Please sign in to comment.