use operator in person search api

This commit is contained in:
Julien Fastré 2021-08-24 00:02:37 +02:00
parent ddd1eb5d10
commit 5884fbaffc
2 changed files with 14 additions and 10 deletions

View File

@ -4,15 +4,15 @@ namespace Chill\MainBundle\Search;
class SearchApiQuery
{
private ?string $selectKey;
private ?string $selectKey = null;
private array $selectKeyParams = [];
private ?string $jsonbMetadata;
private ?string $jsonbMetadata = null;
private array $jsonbMetadataParams = [];
private ?string $pertinence;
private ?string $pertinence = null;
private array $pertinenceParams = [];
private ?string $fromClause;
private ?string $fromClause = null;
private array $fromClauseParams = [];
private ?string $whereClause;
private ?string $whereClause = null;
private array $whereClauseParams = [];
public function setSelectKey(string $selectKey, array $params = []): self
@ -68,7 +68,7 @@ class SearchApiQuery
'{metadata}' => $this->jsonbMetadata,
'{pertinence}' => $this->pertinence,
'{from}' => $this->fromClause,
'{where}' => $this->whereClause
'{where}' => $this->whereClause,
]);
}
@ -79,7 +79,7 @@ class SearchApiQuery
$this->jsonbMetadataParams,
$this->pertinenceParams,
$this->fromClauseParams,
$this->whereClauseParams
$this->whereClauseParams,
);
}
}

View File

@ -14,16 +14,20 @@ class SearchPersonApiProvider implements SearchApiInterface
{
$this->personRepository = $personRepository;
}
public function provideQuery(string $pattern, array $parameters): SearchApiQuery
{
$query = new SearchApiQuery();
$query
->setSelectKey("person")
->setSelectJsonbMetadata("jsonb_build_object('id', person.id)")
->setSelectPertinence("SIMILARITY(LOWER(UNACCENT(?)), person.fullnamecanonical)", [ $pattern ])
->setSelectPertinence("GREATEST(".
"STRICT_WORD_SIMILARITY(LOWER(UNACCENT(?)), person.fullnamecanonical), ".
"(person.fullnamecanonical LIKE '%' || LOWER(UNACCENT(?)) || '%')::int".
")", [ $pattern, $pattern ])
->setFromClause("chill_person_person AS person")
->setWhereClause("SIMILARITY(LOWER(UNACCENT(?)), person.fullnamecanonical) > 0.20", [ $pattern ])
->setWhereClause("LOWER(UNACCENT(?)) <<% person.fullnamecanonical OR ".
"person.fullnamecanonical LIKE '%' || LOWER(UNACCENT(?)) || '%' ", [ $pattern, $pattern ])
;
return $query;