diff --git a/src/Bundle/ChillMainBundle/Search/SearchApi.php b/src/Bundle/ChillMainBundle/Search/SearchApi.php index 4894c0f9a..677286f1f 100644 --- a/src/Bundle/ChillMainBundle/Search/SearchApi.php +++ b/src/Bundle/ChillMainBundle/Search/SearchApi.php @@ -4,9 +4,8 @@ namespace Chill\MainBundle\Search; use Chill\MainBundle\Serializer\Model\Collection; use Chill\MainBundle\Pagination\PaginatorFactory; -use Chill\PersonBundle\Entity\Person; use Chill\PersonBundle\Search\SearchPersonApiProvider; -use Chill\ThirdPartyBundle\Entity\ThirdParty; +use Chill\ThirdPartyBundle\Search\ThirdPartyApiSearch; use Doctrine\DBAL\Types\Types; use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Query\ResultSetMappingBuilder; @@ -18,21 +17,20 @@ use Symfony\Component\VarDumper\Resources\functions\dump; class SearchApi { private EntityManagerInterface $em; - private SearchProvider $search; private PaginatorFactory $paginator; private array $providers = []; public function __construct( EntityManagerInterface $em, - SearchProvider $search, SearchPersonApiProvider $searchPerson, + ThirdPartyApiSearch $thirdPartyApiSearch, PaginatorFactory $paginator ) { $this->em = $em; - $this->search = $search; $this->providers[] = $searchPerson; + $this->providers[] = $thirdPartyApiSearch; $this->paginator = $paginator; } @@ -47,11 +45,9 @@ class SearchApi $paginator = $this->paginator->create($total); $rawResults = $this->fetchRawResult($queries, $types, $parameters, $paginator); - dump($rawResults); $this->prepareProviders($rawResults); $results = $this->buildResults($rawResults); - dump($results); $collection = new Collection($results, $paginator); @@ -169,8 +165,6 @@ class SearchApi } } - dump($items); - return $items ?? []; } } diff --git a/src/Bundle/ChillMainBundle/Search/SearchApiInterface.php b/src/Bundle/ChillMainBundle/Search/SearchApiInterface.php new file mode 100644 index 000000000..54269c946 --- /dev/null +++ b/src/Bundle/ChillMainBundle/Search/SearchApiInterface.php @@ -0,0 +1,18 @@ +setSelectKey("'person'") + ->setSelectKey("person") ->setSelectJsonbMetadata("jsonb_build_object('id', person.id)") ->setSelectPertinence("SIMILARITY(LOWER(UNACCENT(?)), person.fullnamecanonical)", [ $pattern ]) ->setFromClause("chill_person_person AS person") diff --git a/src/Bundle/ChillThirdPartyBundle/Search/ThirdPartyApiSearch.php b/src/Bundle/ChillThirdPartyBundle/Search/ThirdPartyApiSearch.php new file mode 100644 index 000000000..29a341b1b --- /dev/null +++ b/src/Bundle/ChillThirdPartyBundle/Search/ThirdPartyApiSearch.php @@ -0,0 +1,48 @@ +thirdPartyRepository = $thirdPartyRepository; + } + + public function provideQuery(string $pattern, array $parameters): SearchApiQuery + { + return (new SearchApiQuery) + ->setSelectKey('tparty') + ->setSelectJsonbMetadata("jsonb_build_object('id', tparty.id)") + ->setSelectPertinence("SIMILARITY(?, LOWER(UNACCENT(tparty.name)))", [ $pattern ]) + ->setFromClause('chill_3party.third_party AS tparty') + ->setWhereClause('SIMILARITY(LOWER(UNACCENT(?)), LOWER(UNACCENT(tparty.name))) > 0.20', [ $pattern ]) + ; + } + + public function supportsTypes(string $pattern, array $types, array $parameters): bool + { + return \in_array('thirdparty', $types); + } + + public function prepare(array $metadatas): void + { + + } + + public function supportsResult(string $key, array $metadatas): bool + { + return $key === 'tparty'; + } + + public function getResult(string $key, array $metadata, float $pertinence) + { + return $this->thirdPartyRepository->find($metadata['id']); + } +} diff --git a/src/Bundle/ChillThirdPartyBundle/config/services/search.yaml b/src/Bundle/ChillThirdPartyBundle/config/services/search.yaml index f4ff72db9..62b5dd205 100644 --- a/src/Bundle/ChillThirdPartyBundle/config/services/search.yaml +++ b/src/Bundle/ChillThirdPartyBundle/config/services/search.yaml @@ -7,3 +7,7 @@ services: $paginatorFactory: '@Chill\MainBundle\Pagination\PaginatorFactory' tags: - { name: 'chill.search', alias: '3party' } + + Chill\ThirdPartyBundle\Search\ThirdPartyApiSearch: + autowire: true + autoconfigure: true