api endpoint for search household

This commit is contained in:
2022-01-29 01:14:30 +01:00
parent efff496f7a
commit bc90664480
4 changed files with 137 additions and 2 deletions

View File

@@ -22,6 +22,10 @@ class SearchApiQuery
private array $fromClauseParams = [];
private bool $isDistinct = false;
private ?string $isDistinctKey = null;
private ?string $jsonbMetadata = null;
private array $jsonbMetadataParams = [];
@@ -105,6 +109,11 @@ class SearchApiQuery
]);
}
public function getDistinct(): bool
{
return $this->isDistinct;
}
public function getFromClause(): string
{
return $this->fromClause;
@@ -139,6 +148,14 @@ class SearchApiQuery
return $this;
}
public function setDistinct(bool $distinct, string $distinctKey): self
{
$this->isDistinct = $distinct;
$this->isDistinctKey = $distinctKey;
return $this;
}
public function setFromClause(string $fromClause, array $params = []): self
{
$this->fromClause = $fromClause;
@@ -185,7 +202,11 @@ class SearchApiQuery
private function buildSelectClause(bool $countOnly = false): string
{
if ($countOnly) {
return 'count(*) AS c';
if (!$this->isDistinct) {
return 'count(*) AS c';
}
return 'count(distinct ' . $this->isDistinctKey . ') AS c';
}
$selects = $this->getSelectClauses();
@@ -202,7 +223,7 @@ class SearchApiQuery
$selects[] = strtr('{pertinence} AS pertinence', ['{pertinence}' => $this->pertinence]);
}
return implode(', ', $selects);
return ($this->isDistinct ? 'DISTINCT ' : '') . implode(', ', $selects);
}
private function buildSelectParams(bool $count = false): array

View File

@@ -134,6 +134,7 @@ paths:
- search
- person
- thirdparty
- household
description: >
The search is performed across multiple entities. The entities must be listed into
`type` parameters.
@@ -159,6 +160,7 @@ paths:
- person
- thirdparty
- user
- household
responses:
200:
description: "OK"