From 98c2ee3ab26151bd187484802513cc92476a52d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Sat, 15 Jul 2023 08:59:07 +0200 Subject: [PATCH] [Collate Address] when updating address point, do not use the point's address reference if the similarity is below --- .changes/unreleased/Fixed-20230715-085153.yaml | 7 +++++++ .../CollateAddressWithReferenceOrPostalCode.php | 8 +++++++- 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 .changes/unreleased/Fixed-20230715-085153.yaml diff --git a/.changes/unreleased/Fixed-20230715-085153.yaml b/.changes/unreleased/Fixed-20230715-085153.yaml new file mode 100644 index 000000000..9a07ecd36 --- /dev/null +++ b/.changes/unreleased/Fixed-20230715-085153.yaml @@ -0,0 +1,7 @@ +kind: Fixed +body: '[Collate Address] when updating address point, do not use the point''s address + reference if the similarity is below the requirement for associating the address + reference and the address (it uses the postcode''s center instead)' +time: 2023-07-15T08:51:53.293736534+02:00 +custom: + Issue: "" diff --git a/src/Bundle/ChillMainBundle/Service/AddressGeographicalUnit/CollateAddressWithReferenceOrPostalCode.php b/src/Bundle/ChillMainBundle/Service/AddressGeographicalUnit/CollateAddressWithReferenceOrPostalCode.php index 4dc1947c1..2a26034ce 100644 --- a/src/Bundle/ChillMainBundle/Service/AddressGeographicalUnit/CollateAddressWithReferenceOrPostalCode.php +++ b/src/Bundle/ChillMainBundle/Service/AddressGeographicalUnit/CollateAddressWithReferenceOrPostalCode.php @@ -76,11 +76,17 @@ final readonly class CollateAddressWithReferenceOrPostalCode implements CollateA UPDATE chill_main_address SET addressreference_id = recollate.address_reference_id FROM recollate WHERE chill_main_address.id = recollate.address_id; SQL; + /** + * Update the point's address with the: + * + * - address reference point, if the address match the reference with sufficient similarity + * - or the postcal code center + */ private const UPDATE_POINT = <<<'SQL' WITH address_geom AS ( SELECT cma.id AS address_id, COALESCE(cmar.point, cmpc.center) AS point FROM chill_main_address cma - LEFT JOIN chill_main_address_reference cmar ON cma.addressreference_id = cmar.id + LEFT JOIN chill_main_address_reference cmar ON cma.addressreference_id = cmar.id AND similarity(cma.street, cmar.street) > 0.6 AND LOWER(cma.streetnumber) = LOWER(cmar.streetnumber) LEFT JOIN chill_main_postal_code cmpc ON cma.postcode_id = cmpc.id WHERE cma.id > :since_id )