]> git.openstreetmap.org Git - nominatim.git/blobdiff - lib/Geocode.php
use object properties in loadStructuredAddressElement()
[nominatim.git] / lib / Geocode.php
index 0e1d7c1f2787dbf0b33eb32b720495b6cd8daab6..16c40f529fe347592027508201712af564f3ec92 100644 (file)
                        $this->oDB =& $oDB;
                }
 
+               function setReverseInPlan($bReverse)
+               {
+                       $this->bReverseInPlan = $bReverse;
+               }
+
                function setLanguagePreference($aLangPref)
                {
                        $this->aLangPrefOrder = $aLangPref;
                        return $this->sQuery;
                }
 
+               function loadStructuredAddressElement($sValue, $sKey, $iNewMinAddressRank, $iNewMaxAddressRank, $aItemListValues)
+               {
+                       $sValue = trim($sValue);
+                       if (!$sValue) return false;
+                       $this->aStructuredQuery[$sKey] = $sValue;
+                       if ($this->iMinAddressRank == 0 && $this->iMaxAddressRank == 30)
+                       {
+                               $this->iMinAddressRank = $iNewMinAddressRank;
+                               $this->iMaxAddressRank = $iNewMaxAddressRank;
+                       }
+                       if ($aItemListValues) $this->aAddressRankList = array_merge($this->aAddressRankList, $aItemListValues);
+                       return true;
+               }
+
                function setStructuredQuery($sAmentiy = false, $sStreet = false, $sCity = false, $sCounty = false, $sState = false, $sCountry = false, $sPostalCode = false)
                {
                        $this->sQuery = false;
                        $this->aStructuredQuery = array();
                        $this->sAllowedTypesSQLList = '';
 
-                       loadStructuredAddressElement($this->aStructuredQuery, $this->iMinAddressRank, $this->iMaxAddressRank, $this->aAddressRankList, $sAmentiy, 'amenity', 26, 30, false);
-                       loadStructuredAddressElement($this->aStructuredQuery, $this->iMinAddressRank, $this->iMaxAddressRank, $this->aAddressRankList, $sStreet, 'street', 26, 30, false);
-                       loadStructuredAddressElement($this->aStructuredQuery, $this->iMinAddressRank, $this->iMaxAddressRank, $this->aAddressRankList, $sCity, 'city', 14, 24, false);
-                       loadStructuredAddressElement($this->aStructuredQuery, $this->iMinAddressRank, $this->iMaxAddressRank, $this->aAddressRankList, $sCounty, 'county', 9, 13, false);
-                       loadStructuredAddressElement($this->aStructuredQuery, $this->iMinAddressRank, $this->iMaxAddressRank, $this->aAddressRankList, $sState, 'state', 8, 8, false);
-                       loadStructuredAddressElement($this->aStructuredQuery, $this->iMinAddressRank, $this->iMaxAddressRank, $this->aAddressRankList, $sCountry, 'country', 4, 4, false);
-                       loadStructuredAddressElement($this->aStructuredQuery, $this->iMinAddressRank, $this->iMaxAddressRank, $this->aAddressRankList, $sPostalCode, 'postalcode' , 5, 11, array(5, 11));
+                       $this->loadStructuredAddressElement($sAmentiy, 'amenity', 26, 30, false);
+                       $this->loadStructuredAddressElement($sStreet, 'street', 26, 30, false);
+                       $this->loadStructuredAddressElement($sCity, 'city', 14, 24, false);
+                       $this->loadStructuredAddressElement($sCounty, 'county', 9, 13, false);
+                       $this->loadStructuredAddressElement($sState, 'state', 8, 8, false);
+                       $this->loadStructuredAddressElement($sPostalCode, 'postalcode' , 5, 11, array(5, 11));
+                       $this->loadStructuredAddressElement($sCountry, 'country', 4, 4, false);
 
                        if (sizeof($this->aStructuredQuery) > 0) 
                        {
                        $sSQL .= "from placex where place_id in ($sPlaceIDs) ";
                        $sSQL .= "and (placex.rank_address between $this->iMinAddressRank and $this->iMaxAddressRank ";
                        if (14 >= $this->iMinAddressRank && 14 <= $this->iMaxAddressRank) $sSQL .= " OR (extratags->'place') = 'city'";
-                       if ($aAddressRankList) $sSQL .= " OR placex.rank_address in (".join(',',$aAddressRankList).")";
+                       if ($this->aAddressRankList) $sSQL .= " OR placex.rank_address in (".join(',',$this->aAddressRankList).")";
                        $sSQL .= ") ";
                        if ($this->sAllowedTypesSQLList) $sSQL .= "and placex.class in $this->sAllowedTypesSQLList ";
                        $sSQL .= "and linked_place_id is null ";
                                                if ($bStructuredPhrases) $sPhraseType = $aPhraseTypes[$iPhrase];
                                                else $sPhraseType = '';
 
-                                               foreach($aPhrases[$iPhrase]['wordsets'] as $aWordset)
+                                               foreach($aPhrases[$iPhrase]['wordsets'] as $iWordSet => $aWordset)
                                                {
+                                                       // Too many permutations - too expensive
+                                                       if ($iWordSet > 120) break;
+
                                                        $aWordsetSearches = $aSearches;
 
                                                        // Add all words from this wordset