X-Git-Url: https://git.openstreetmap.org/nominatim.git/blobdiff_plain/34adfd504104fa941f6edbfa155b990ef7b3d77b..8c7f8165bdb611f48c0ae63f9318c8490138ffea:/lib/Geocode.php diff --git a/lib/Geocode.php b/lib/Geocode.php index 92e1a0b3..0b3bd51f 100644 --- a/lib/Geocode.php +++ b/lib/Geocode.php @@ -518,7 +518,7 @@ foreach($this->aRoutePoints as $aPoint) { if (!$bFirst) $sViewboxCentreSQL .= ","; - $sViewboxCentreSQL .= $aPoint[1].' '.$aPoint[0]; + $sViewboxCentreSQL .= $aPoint[0].' '.$aPoint[1]; $bFirst = false; } $sViewboxCentreSQL .= ")'::geometry,4326)"; @@ -890,6 +890,9 @@ if ($aSearch['sHouseNumber'] === '') { $aSearch['sHouseNumber'] = $sToken; + // sanity check: if the housenumber is not mainly made + // up of numbers, add a penalty + if (preg_match_all("/[^0-9]/", $sToken, $aMatches) > 2) $aSearch['iSearchRank']++; if ($aSearch['iSearchRank'] < $this->iMaxRank) $aNewWordsetSearches[] = $aSearch; /* // Fall back to not searching for this item (better than nothing) @@ -908,7 +911,7 @@ $aSearch['sType'] = $aSearchTerm['type']; if (sizeof($aSearch['aName'])) $aSearch['sOperator'] = 'name'; else $aSearch['sOperator'] = 'near'; // near = in for the moment - if (strlen($aSearchTerm['operator']) == 0) $aSearch['iSearchRank'] += 1; + if (strlen($aSearchTerm['operator']) == 0) $aSearch['iSearchRank'] += 1; // Do we have a shortcut id? if ($aSearch['sOperator'] == 'name') @@ -1178,6 +1181,10 @@ if (CONST_Debug) var_dump($sSQL); $aPlaceIDs = $this->oDB->getCol($sSQL); } + else + { + $aPlaceIDs = array(); + } } else { @@ -1202,7 +1209,8 @@ // If excluded place IDs are given, it is fair to assume that // there have been results in the small box, so no further // expansion in that case. - if (!sizeof($aPlaceIDs) && !sizeof($this->aExcludePlaceIDs)) + // Also don't expand if bounded results were requested. + if (!sizeof($aPlaceIDs) && !sizeof($this->aExcludePlaceIDs) && !$this->bBoundedSearch) { $sSQL = "select place_id from place_classtype_".$aSearch['sClass']."_".$aSearch['sType']." ct"; if ($sCountryCodesSQL) $sSQL .= " join placex using (place_id)"; @@ -1254,7 +1262,21 @@ } } if ($aSearch['sCountryCode']) $aTerms[] = "country_code = '".pg_escape_string($aSearch['sCountryCode'])."'"; - if ($aSearch['sHouseNumber']) $aTerms[] = "address_rank between 16 and 27"; + if ($aSearch['sHouseNumber']) + { + $aTerms[] = "address_rank between 16 and 27"; + } + else + { + if ($this->iMinAddressRank > 0) + { + $aTerms[] = "address_rank >= ".$this->iMinAddressRank; + } + if ($this->iMaxAddressRank < 30) + { + $aTerms[] = "address_rank <= ".$this->iMaxAddressRank; + } + } if ($aSearch['fLon'] && $aSearch['fLat']) { $aTerms[] = "ST_DWithin(centroid, ST_SetSRID(ST_Point(".$aSearch['fLon'].",".$aSearch['fLat']."),4326), ".$aSearch['fRadius'].")"; @@ -1335,8 +1357,8 @@ $sPlaceIDs = join(',',$aPlaceIDs); // Now they are indexed look for a house attached to a street we found - $sHouseNumberRegex = '\\\\m'.str_replace(' ','[-,/ ]',$aSearch['sHouseNumber']).'\\\\M'; - $sSQL = "select place_id from placex where parent_place_id in (".$sPlaceIDs.") and housenumber ~* E'".$sHouseNumberRegex."'"; + $sHouseNumberRegex = '\\\\m'.$aSearch['sHouseNumber'].'\\\\M'; + $sSQL = "select place_id from placex where parent_place_id in (".$sPlaceIDs.") and transliteration(housenumber) ~* E'".$sHouseNumberRegex."'"; if (sizeof($this->aExcludePlaceIDs)) { $sSQL .= " and place_id not in (".join(',',$this->aExcludePlaceIDs).")"; @@ -1459,7 +1481,7 @@ } if ($sCountryCodesSQL) $sSQL .= " and lp.calculated_country_code in ($sCountryCodesSQL)"; if ($sOrderBySQL) $sSQL .= "order by ".$sOrderBySQL." asc"; - if ($iOffset) $sSQL .= " offset $iOffset"; + if ($this->iOffset) $sSQL .= " offset $this->iOffset"; $sSQL .= " limit $this->iLimit"; if (CONST_Debug) var_dump($sSQL); $aClassPlaceIDs = array_merge($aClassPlaceIDs, $this->oDB->getCol($sSQL)); @@ -1481,7 +1503,7 @@ } if ($sCountryCodesSQL) $sSQL .= " and l.calculated_country_code in ($sCountryCodesSQL)"; if ($sOrderBy) $sSQL .= "order by ".$OrderBysSQL." asc"; - if ($iOffset) $sSQL .= " offset $iOffset"; + if ($this->iOffset) $sSQL .= " offset $this->iOffset"; $sSQL .= " limit $this->iLimit"; if (CONST_Debug) var_dump($sSQL); $aClassPlaceIDs = array_merge($aClassPlaceIDs, $this->oDB->getCol($sSQL)); @@ -1562,7 +1584,7 @@ } $aClassType = getClassTypesWithImportance(); - $aRecheckWords = preg_split('/\b/u',$sQuery); + $aRecheckWords = preg_split('/\b[\s,\\-]*/u',$sQuery); foreach($aRecheckWords as $i => $sWord) { if (!$sWord) unset($aRecheckWords[$i]); @@ -1723,7 +1745,11 @@ $sAddress = $aResult['langaddress']; foreach($aRecheckWords as $i => $sWord) { - if (stripos($sAddress, $sWord)!==false) $iCountWords++; + if (stripos($sAddress, $sWord)!==false) + { + $iCountWords++; + if (preg_match("/(^|,)\s*$sWord\s*(,|$)/", $sAddress)) $iCountWords += 0.1; + } } $aResult['importance'] = $aResult['importance'] + ($iCountWords*0.1); // 0.1 is a completely arbitrary number but something in the range 0.1 to 0.5 would seem right @@ -1787,17 +1813,3 @@ } // end class - -/* - if (isset($_GET['route']) && $_GET['route'] && isset($_GET['routewidth']) && $_GET['routewidth']) - { - $aPoints = explode(',',$_GET['route']); - if (sizeof($aPoints) % 2 != 0) - { - userError("Uneven number of points"); - exit; - } - $sViewboxCentreSQL = "ST_SetSRID('LINESTRING("; - $fPrevCoord = false; - } -*/