From 7d2b6879c87fea1739b85d3a6b232402de45a718 Mon Sep 17 00:00:00 2001 From: Sarah Hoffmann Date: Tue, 6 Oct 2020 14:00:43 +0200 Subject: [PATCH] restrict postcode searches to postcode in first token In structured queries we should only assume that it is a postcode search when only the postcode and optionally the country is given. If any other term is present, it is better to avoid the search for postcode as it yields too many bad searches. Given that the terms in a structured query are ordered, this means that the postcode must be the first token just like in the unstructured query. Fixes #1988. --- lib/SearchDescription.php | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/lib/SearchDescription.php b/lib/SearchDescription.php index 33b766a5..ad404528 100644 --- a/lib/SearchDescription.php +++ b/lib/SearchDescription.php @@ -199,15 +199,10 @@ class SearchDescription } elseif (($sPhraseType == '' || $sPhraseType == 'postalcode') && is_a($oSearchTerm, '\Nominatim\Token\Postcode') ) { - // We need to try the case where the postal code is the primary element - // (i.e. no way to tell if it is (postalcode, city) OR (city, postalcode) - // so try both. if (!$this->sPostcode) { // If we have structured search or this is the first term, // make the postcode the primary search element. - if ($this->iOperator == Operator::NONE - && ($sPhraseType == 'postalcode' || $bFirstToken) - ) { + if ($this->iOperator == Operator::NONE && $bFirstToken) { $oSearch = clone $this; $oSearch->iSearchRank++; $oSearch->iOperator = Operator::POSTCODE; -- 2.45.2