fix(search): share provincial hierarchy across legacy and catalogue APIs

This commit is contained in:
2026-10-29 14:13:40 +02:00
parent 979f3f850e
commit fdadc8ace7
7 changed files with 276 additions and 33 deletions
+15
View File
@@ -12,6 +12,21 @@ final class InvestmentGeography
{
public const FIELDS = ['province_id' => 'province', 'district_id' => 'district', 'admin_post_id' => 'admin_post', 'locality_id' => 'locality'];
/** Resolve an old province-name search only when the public register has exactly one match. */
public function provinceSearch(array $filters): array
{
if (empty($filters['province_id']) && is_string($filters['province'] ?? null) && trim($filters['province']) !== '') {
$matches = $this->publicReferences()->where('location_type', 'province')
->whereRaw('lower(btrim(name)) = ?', [mb_strtolower(trim($filters['province']))])->limit(2)->get(['id']);
if ($matches->count() === 1) {
$filters['province_id'] = $matches[0]->id;
unset($filters['province']);
}
}
return $filters;
}
/**
* Restrict published dossier searches using direct territories and public, validated structure links.
*