X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/ec2d491dc8939ecf28ab84e26955bc7189618096..22800d7d59f952ced174008669e5eddadf1117d8:/lib/SearchDescription.php diff --git a/lib/SearchDescription.php b/lib/SearchDescription.php index 358e6969..c339b108 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; @@ -252,6 +247,15 @@ class SearchDescription $oSearch->iSearchRank++; } $aNewSearches[] = $oSearch; + // Housenumbers may appear in the name when the place has its own + // address terms. + if (($this->iNamePhrase >= 0 || empty($this->aName)) && empty($this->aAddress)) { + $oSearch = clone $this; + $oSearch->iSearchRank++; + $oSearch->aAddress = $this->aName; + $oSearch->aName = array($oSearchTerm->iId => $oSearchTerm->iId); + $aNewSearches[] = $oSearch; + } } } elseif ($sPhraseType == '' && is_a($oSearchTerm, '\Nominatim\Token\SpecialTerm') @@ -447,8 +451,8 @@ class SearchDescription $iLimit ); - //now search for housenumber, if housenumber provided - if ($this->sHouseNumber && !empty($aResults)) { + // Now search for housenumber, if housenumber provided. Can be zero. + if (($this->sHouseNumber || $this->sHouseNumber === '0') && !empty($aResults)) { // Downgrade the rank of the street results, they are missing // the housenumber. foreach ($aResults as $oRes) { @@ -588,6 +592,9 @@ class SearchDescription $sSQL .= "p.postcode = '".reset($this->aName)."'"; $sSQL .= $this->countryCodeSQL(' AND p.country_code'); + if ($this->oContext->bViewboxBounded) { + $sSQL .= ' AND ST_Intersects('.$this->oContext->sqlViewboxSmall.', geometry)'; + } $sSQL .= $this->oContext->excludeSQL(' AND p.place_id'); $sSQL .= " LIMIT $iLimit"; @@ -654,13 +661,10 @@ class SearchDescription } if ($this->sHouseNumber) { - $aTerms[] = 'address_rank between 16 and 27'; + $aTerms[] = 'address_rank between 16 and 30'; } elseif (!$this->sClass || $this->iOperator == Operator::NAME) { if ($iMinAddressRank > 0) { - $aTerms[] = 'address_rank >= '.$iMinAddressRank; - } - if ($iMaxAddressRank < 30) { - $aTerms[] = 'address_rank <= '.$iMaxAddressRank; + $aTerms[] = "((address_rank between $iMinAddressRank and $iMaxAddressRank) or (search_rank between $iMinAddressRank and $iMaxAddressRank))"; } }