implementation on 3party + quote keys in SearchApiQuery

This commit is contained in:
2021-06-28 22:44:42 +02:00
parent e845d9ba90
commit 0640631821
6 changed files with 77 additions and 12 deletions

View File

@@ -0,0 +1,48 @@
<?php
namespace Chill\ThirdPartyBundle\Search;
use Chill\MainBundle\Search\SearchApiInterface;
use Chill\MainBundle\Search\SearchApiQuery;
use Chill\ThirdPartyBundle\Repository\ThirdPartyRepository;
class ThirdPartyApiSearch implements SearchApiInterface
{
private ThirdPartyRepository $thirdPartyRepository;
public function __construct(ThirdPartyRepository $thirdPartyRepository)
{
$this->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']);
}
}

View File

@@ -7,3 +7,7 @@ services:
$paginatorFactory: '@Chill\MainBundle\Pagination\PaginatorFactory'
tags:
- { name: 'chill.search', alias: '3party' }
Chill\ThirdPartyBundle\Search\ThirdPartyApiSearch:
autowire: true
autoconfigure: true