X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/464fb913a8fcdc9b3f44647cd4cc0f3c1bc67c67..d5e9fc4a0390493361dd3bc58991dd75dc6ed28e:/website/search.php?ds=sidebyside diff --git a/website/search.php b/website/search.php index 7cecb9ed..18fcbafc 100755 --- a/website/search.php +++ b/website/search.php @@ -447,6 +447,28 @@ $aValidTokens[$sToken] = $aGBPostcodeLocation; } } + // US ZIP+4 codes - if there is no token, + // merge in the 5-digit ZIP code + else if (!isset($aValidTokens[$sToken]) && preg_match('/^([0-9]{5}) [0-9]{4}$/', $sToken, $aData)) + { + if (isset($aValidTokens[$aData[1]])) + { + foreach($aValidTokens[$aData[1]] as $aToken) + { + if (!$aToken['class']) + { + if (isset($aValidTokens[$sToken])) + { + $aValidTokens[$sToken][] = $aToken; + } + else + { + $aValidTokens[$sToken] = array($aToken); + } + } + } + } + } } foreach($aTokens as $sToken) @@ -466,7 +488,6 @@ /* Calculate all searches using aValidTokens i.e. - 'Wodsworth Road, Sheffield' => Phrase Wordset @@ -533,13 +554,38 @@ elseif ($sPhraseType == 'postalcode') { // 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 (sizeof($aSearch['aName'])) + if (isset($aSearchTerm['word_id']) && $aSearchTerm['word_id']) { - $aSearch['aAddress'] = array_merge($aSearch['aAddress'], $aSearch['aName']); - $aSearch['aName'] = array(); - $aSearch['aName'][$aSearchTerm['word_id']] = $aSearchTerm['word_id']; + // If we already have a name try putting the postcode first + if (sizeof($aSearch['aName'])) + { + $aNewSearch = $aSearch; + $aNewSearch['aAddress'] = array_merge($aNewSearch['aAddress'], $aNewSearch['aName']); + $aNewSearch['aName'] = array(); + $aNewSearch['aName'][$aSearchTerm['word_id']] = $aSearchTerm['word_id']; + if ($aSearch['iSearchRank'] < $iMaxRank) $aNewWordsetSearches[] = $aNewSearch; + } + + if (sizeof($aSearch['aName'])) + { + if ((!$bStructuredPhrases || $iPhrase > 0) && $sPhraseType != 'country' && (!isset($aValidTokens[$sToken]) || strlen($sToken) < 4 || strpos($sToken, ' ') !== false)) + { + $aSearch['aAddress'][$aSearchTerm['word_id']] = $aSearchTerm['word_id']; + } + else + { + $aCurrentSearch['aFullNameAddress'][$aSearchTerm['word_id']] = $aSearchTerm['word_id']; + $aSearch['iSearchRank'] += 1000; // skip; + } + } + else + { + $aSearch['aName'][$aSearchTerm['word_id']] = $aSearchTerm['word_id']; + //$aSearch['iNamePhrase'] = $iPhrase; + } + if ($aSearch['iSearchRank'] < $iMaxRank) $aNewWordsetSearches[] = $aSearch; } - if ($aSearch['iSearchRank'] < $iMaxRank) $aNewWordsetSearches[] = $aSearch; + } elseif (($sPhraseType == '' || $sPhraseType == 'street') && $aSearchTerm['class'] == 'place' && $aSearchTerm['type'] == 'house') { @@ -708,6 +754,7 @@ //if (CONST_Debug) _debugDumpGroupedSearches($aGroupedSearches, $aValidTokens); } + } else {