mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
use operator in person search api
This commit is contained in:
parent
ddd1eb5d10
commit
5884fbaffc
@ -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,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user