Merge remote-tracking branch 'origin/master' into features/improve-accompanying-course-summary

This commit is contained in:
2021-06-29 16:59:05 +02:00
16 changed files with 585 additions and 55 deletions

View File

@@ -37,6 +37,11 @@ final class PersonRepository
return $this->repository->find($id, $lockMode, $lockVersion);
}
public function findByIds($ids): array
{
return $this->repository->findBy(['id' => $ids]);
}
/**
* @param $centers
* @param $firstResult

View File

@@ -0,0 +1,53 @@
<?php
namespace Chill\PersonBundle\Search;
use Chill\PersonBundle\Repository\PersonRepository;
use Chill\MainBundle\Search\SearchApiQuery;
use Chill\MainBundle\Search\SearchApiInterface;
class SearchPersonApiProvider implements SearchApiInterface
{
private PersonRepository $personRepository;
public function __construct(PersonRepository $personRepository)
{
$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 ])
->setFromClause("chill_person_person AS person")
->setWhereClause("SIMILARITY(LOWER(UNACCENT(?)), person.fullnamecanonical) > 0.20", [ $pattern ])
;
return $query;
}
public function supportsTypes(string $pattern, array $types, array $parameters): bool
{
return \in_array('person', $types);
}
public function prepare(array $metadatas): void
{
$ids = \array_map(fn($m) => $m['id'], $metadatas);
$this->personRepository->findByIds($ids);
}
public function supportsResult(string $key, array $metadatas): bool
{
return $key === 'person';
}
public function getResult(string $key, array $metadata, float $pertinence)
{
return $this->personRepository->find($metadata['id']);
}
}

View File

@@ -28,3 +28,7 @@ services:
$em: '@Doctrine\ORM\EntityManagerInterface'
$tokenStorage: '@Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface'
$authorizationHelper: '@Chill\MainBundle\Security\Authorization\AuthorizationHelper'
Chill\PersonBundle\Search\SearchPersonApiProvider:
autowire: true
autoconfigure: true