From: Sarah Hoffmann Date: Tue, 6 Oct 2020 12:00:43 +0000 (+0200) Subject: restrict postcode searches to postcode in first token X-Git-Tag: v3.6.0~58^2 X-Git-Url: https://git.openstreetmap.org./nominatim.git/commitdiff_plain/7d2b6879c87fea1739b85d3a6b232402de45a718?ds=sidebyside 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. --- 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;