mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-20 22:53:49 +00:00
cs: Fix code style (safe rules only).
This commit is contained in:
@@ -1,12 +1,21 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\ThirdPartyBundle\Search;
|
||||
|
||||
use Chill\MainBundle\Search\SearchApiInterface;
|
||||
use Chill\MainBundle\Search\SearchApiQuery;
|
||||
use Chill\ThirdPartyBundle\Repository\ThirdPartyRepository;
|
||||
use function array_merge;
|
||||
use function explode;
|
||||
|
||||
use function implode;
|
||||
use function in_array;
|
||||
|
||||
/*
|
||||
* Internal note: test query for parametrizing / testing:
|
||||
@@ -33,7 +42,7 @@ FROM rows, searches
|
||||
*/
|
||||
|
||||
/**
|
||||
* Generate query for searching amongst third parties
|
||||
* Generate query for searching amongst third parties.
|
||||
*/
|
||||
class ThirdPartyApiSearch implements SearchApiInterface
|
||||
{
|
||||
@@ -44,9 +53,18 @@ class ThirdPartyApiSearch implements SearchApiInterface
|
||||
$this->thirdPartyRepository = $thirdPartyRepository;
|
||||
}
|
||||
|
||||
public function getResult(string $key, array $metadata, float $pertinence)
|
||||
{
|
||||
return $this->thirdPartyRepository->find($metadata['id']);
|
||||
}
|
||||
|
||||
public function prepare(array $metadatas): void
|
||||
{
|
||||
}
|
||||
|
||||
public function provideQuery(string $pattern, array $parameters): SearchApiQuery
|
||||
{
|
||||
$query = (new SearchApiQuery)
|
||||
$query = (new SearchApiQuery())
|
||||
->setSelectKey('tparty')
|
||||
->setSelectJsonbMetadata("jsonb_build_object('id', tparty.id)")
|
||||
->setFromClause('chill_3party.third_party AS tparty
|
||||
@@ -55,8 +73,7 @@ class ThirdPartyApiSearch implements SearchApiInterface
|
||||
LEFT JOIN chill_3party.third_party AS parent ON tparty.parent_id = parent.id
|
||||
LEFT JOIN chill_main_address cma_p ON parent.address_id = cma_p.id
|
||||
LEFT JOIN chill_main_postal_code cmpc_p ON cma_p.postcode_id = cmpc.id')
|
||||
->andWhereClause("tparty.active IS TRUE")
|
||||
;
|
||||
->andWhereClause('tparty.active IS TRUE');
|
||||
|
||||
$strs = explode(' ', $pattern);
|
||||
$wheres = [];
|
||||
@@ -65,45 +82,39 @@ class ThirdPartyApiSearch implements SearchApiInterface
|
||||
$pertinenceArgs = [];
|
||||
|
||||
foreach ($strs as $str) {
|
||||
if (!empty($str)) {
|
||||
$wheres[] = "(LOWER(UNACCENT(?)) <<% tparty.canonicalized OR
|
||||
if (!empty($str)) {
|
||||
$wheres[] = "(LOWER(UNACCENT(?)) <<% tparty.canonicalized OR
|
||||
tparty.canonicalized LIKE '%' || LOWER(UNACCENT(?)) || '%')";
|
||||
$whereArgs[] = [$str, $str];
|
||||
$pertinence[] = "STRICT_WORD_SIMILARITY(LOWER(UNACCENT(?)), tparty.canonicalized) + ".
|
||||
"(tparty.canonicalized LIKE '%s' || LOWER(UNACCENT(?)) || '%')::int + ".
|
||||
$whereArgs[] = [$str, $str];
|
||||
$pertinence[] = 'STRICT_WORD_SIMILARITY(LOWER(UNACCENT(?)), tparty.canonicalized) + ' .
|
||||
"(tparty.canonicalized LIKE '%s' || LOWER(UNACCENT(?)) || '%')::int + " .
|
||||
// take postcode label into account, but lower than the canonicalized field
|
||||
"COALESCE((LOWER(UNACCENT(cmpc.label)) LIKE '%' || LOWER(UNACCENT(?)) || '%')::int * 0.3, 0) + ".
|
||||
"COALESCE((LOWER(UNACCENT(cmpc.label)) LIKE '%' || LOWER(UNACCENT(?)) || '%')::int * 0.3, 0) + " .
|
||||
"COALESCE((LOWER(UNACCENT(cmpc_p.label)) LIKE '%' || LOWER(UNACCENT(?)) || '%')::int * 0.3, 0)";
|
||||
$pertinenceArgs[] = [$str, $str, $str, $str];
|
||||
}
|
||||
$pertinenceArgs[] = [$str, $str, $str, $str];
|
||||
}
|
||||
}
|
||||
|
||||
$query
|
||||
->setSelectPertinence(\implode(' + ', $pertinence), \array_merge([],
|
||||
...$pertinenceArgs))
|
||||
->andWhereClause(\implode(' OR ', $wheres), \array_merge([],
|
||||
...$whereArgs));
|
||||
->setSelectPertinence(implode(' + ', $pertinence), array_merge(
|
||||
[],
|
||||
...$pertinenceArgs
|
||||
))
|
||||
->andWhereClause(implode(' OR ', $wheres), array_merge(
|
||||
[],
|
||||
...$whereArgs
|
||||
));
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
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';
|
||||
return 'tparty' === $key;
|
||||
}
|
||||
|
||||
public function getResult(string $key, array $metadata, float $pertinence)
|
||||
public function supportsTypes(string $pattern, array $types, array $parameters): bool
|
||||
{
|
||||
return $this->thirdPartyRepository->find($metadata['id']);
|
||||
return in_array('thirdparty', $types);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user