]> git.openstreetmap.org Git - nominatim.git/commitdiff
Try alternative orderings of structured queries that include postal codes
authorBrian Quinion <brian.quinion@mapquest.com>
Tue, 11 Jun 2013 13:56:50 +0000 (14:56 +0100)
committerBrian Quinion <brian.quinion@mapquest.com>
Tue, 11 Jun 2013 13:56:50 +0000 (14:56 +0100)
lib/lib.php
website/search.php

index 1517b317102502d75b175ee39949c96af8ce9434..3b16b399a6e9eb9001ac2755073ba491836657dd 100644 (file)
                return $iPlaceID;
        }
 
-       function loadStructuredAddressElement(&$aStructuredQuery, &$iMinAddressRank, &$iMaxAddressRank, $aParams, $sKey, $iNewMinAddressRank, $iNewMaxAddressRank)
+       function loadStructuredAddressElement(&$aStructuredQuery, &$iMinAddressRank, &$iMaxAddressRank, &$aAddressRankList, $aParams, $sKey, $iNewMinAddressRank, $iNewMaxAddressRank, $aItemListValues)
        {
                if (!isset($_GET[$sKey])) return false;
                $sValue = trim($_GET[$sKey]);
                        $iMinAddressRank = $iNewMinAddressRank;
                        $iMaxAddressRank = $iNewMaxAddressRank;
                }
+               if ($aItemListValues) $aAddressRankList = array_merge($aAddressRankList, $aItemListValues);
                return true;
        }
index 3eb50aa20bc1e4b3aceb7dce96bb4fcf3d32ea9f..76daa98c4bd73b1dee7bca99a62ced7f460b60e0 100755 (executable)
@@ -26,6 +26,7 @@
        $iLimit = $iFinalLimit + min($iFinalLimit, 10);
        $iMinAddressRank = 0;
        $iMaxAddressRank = 30;
+       $aAddressRankList = array();
        $sAllowedTypesSQLList = false;
 
        // Format for output
 
        // Structured query?
        $aStructuredOptions = array(
-                               array('amenity', 26, 30),
-                               array('street', 26, 30),
-                               array('city', 14, 24),
-                               array('county', 9, 13),
-                               array('state', 8, 8),
-                               array('country', 4, 4),
-                               array('postalcode', 5, 11),
+                               array('amenity', 26, 30, false),
+                               array('street', 26, 30, false),
+                               array('city', 14, 24, false),
+                               array('postalcode', 5, 11, array(5, 11)),
+                               array('county', 9, 13, false),
+                               array('state', 8, 8, false),
+                               array('country', 4, 4, false),
                                );
        $aStructuredQuery = array();
        $sAllowedTypesSQLList = '';
        foreach($aStructuredOptions as $aStructuredOption)
        {
-               loadStructuredAddressElement($aStructuredQuery, $iMinAddressRank, $iMaxAddressRank, $_GET, $aStructuredOption[0], $aStructuredOption[1], $aStructuredOption[2]);
+               loadStructuredAddressElement($aStructuredQuery, $iMinAddressRank, $iMaxAddressRank, $aAddressRankList, $_GET, $aStructuredOption[0], $aStructuredOption[1], $aStructuredOption[2], $aStructuredOption[3]);
        }
        if (sizeof($aStructuredQuery) > 0) 
        {
                                $bStructuredPhrases = false;
                        }
 
-
                        // Convert each phrase to standard form
                        // Create a list of standard words
                        // Get all 'sets' of words
                                                                                                if ($aSearch['iSearchRank'] < $iMaxRank) $aNewWordsetSearches[] = $aSearch;
                                                                                        }
                                                                                }
+                                                                               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']))
+                                                                                       {
+                                                                                               $aSearch['aAddress'] = array_merge($aSearch['aAddress'], $aSearch['aName']);
+                                                                                               $aSearch['aName'] = array();
+                                                                                               $aSearch['aName'][$aSearchTerm['word_id']] = $aSearchTerm['word_id'];
+                                                                                       }
+                                                                                       if ($aSearch['iSearchRank'] < $iMaxRank) $aNewWordsetSearches[] = $aSearch;
+                                                                               }
                                                                                elseif (($sPhraseType == '' || $sPhraseType == 'street') && $aSearchTerm['class'] == 'place' && $aSearchTerm['type'] == 'house')
                                                                                {
                                                                                        if ($aSearch['sHouseNumber'] === '')
                                $sSQL .= "from placex where place_id in ($sPlaceIDs) ";
                                $sSQL .= "and (placex.rank_address between $iMinAddressRank and $iMaxAddressRank ";
                                if (14 >= $iMinAddressRank && 14 <= $iMaxAddressRank) $sSQL .= " OR (extratags->'place') = 'city'";
+                               if ($aAddressRankList) $sSQL .= " OR placex.rank_address in (".join(',',$aAddressRankList).")";
                                $sSQL .= ") ";
                                if ($sAllowedTypesSQLList) $sSQL .= "and placex.class in $sAllowedTypesSQLList ";
                                $sSQL .= "and linked_place_id is null ";
                                        $sSQL .= "from placex where place_id in ($sPlaceIDs) ";
                                        $sSQL .= "and (placex.rank_address between $iMinAddressRank and $iMaxAddressRank ";
                                        if (14 >= $iMinAddressRank && 14 <= $iMaxAddressRank) $sSQL .= " OR (extratags->'place') = 'city'";
+                                       if ($aAddressRankList) $sSQL .= " OR placex.rank_address in (".join(',',$aAddressRankList).")";
                                        $sSQL .= ") ";
                                        $sSQL .= "group by osm_type,osm_id,class,type,admin_level,rank_search,rank_address,calculated_country_code,importance";
                                        if (!$bDeDupe) $sSQL .= ",place_id";