]> git.openstreetmap.org Git - nominatim.git/blobdiff - lib/lib.php
Merge remote-tracking branch 'upstream/master'
[nominatim.git] / lib / lib.php
index 62ffa29368cd067973c67517efd148201449a143..482e95981cc04b7aab021eb82e979c9e950727a9 100644 (file)
                                arsort($aLanguages);
                        }
                }
                                arsort($aLanguages);
                        }
                }
-               if (!sizeof($aLanguages)) $aLanguages = array(CONST_Default_Language=>1);
+               if (!sizeof($aLanguages) && CONST_Default_Language) $aLanguages = array(CONST_Default_Language=>1);
                foreach($aLanguages as $sLangauge => $fLangauagePref)
                {
                        $aLangPrefOrder['short_name:'.$sLangauge] = 'short_name:'.$sLangauge;
                foreach($aLanguages as $sLangauge => $fLangauagePref)
                {
                        $aLangPrefOrder['short_name:'.$sLangauge] = 'short_name:'.$sLangauge;
        }
 
 
        }
 
 
-       function getWordSets($aWords)
+       function getWordSets($aWords, $iDepth)
        {
                $aResult = array(array(join(' ',$aWords)));
                $sFirstToken = '';
        {
                $aResult = array(array(join(' ',$aWords)));
                $sFirstToken = '';
-               while(sizeof($aWords) > 1)
-               {
-                       $sWord = array_shift($aWords);
-                       $sFirstToken .= ($sFirstToken?' ':'').$sWord;
-                       $aRest = getWordSets($aWords);
-                       foreach($aRest as $aSet)
+               if ($iDepth < 7) {
+                       while(sizeof($aWords) > 1)
                        {
                        {
-                               $aResult[] = array_merge(array($sFirstToken),$aSet);
+                               $sWord = array_shift($aWords);
+                               $sFirstToken .= ($sFirstToken?' ':'').$sWord;
+                               $aRest = getWordSets($aWords, $iDepth+1);
+                               foreach($aRest as $aSet)
+                               {
+                                       $aResult[] = array_merge(array($sFirstToken),$aSet);
+                               }
                        }
                }
                return $aResult;
                        }
                }
                return $aResult;
 
                if (sizeof($aNearPostcodes))
                {
 
                if (sizeof($aNearPostcodes))
                {
-                       return array(array('lat' => $aNearPostcodes[0]['lat'], 'lon' => $aNearPostcodes[0]['lon'], 'radius' => 0.005));
+                       $aPostcodes = array();
+                       foreach($aNearPostcodes as $aPostcode)
+                       {
+                               $aPostcodes[] = array('lat' => $aPostcode['lat'], 'lon' => $aPostcode['lon'], 'radius' => 0.005);
+                       }
+
+                       return $aPostcodes;
                }
 
                return false;
                }
 
                return false;
        }
 
 
        }
 
 
-       function getWordSuggestions(&$oDB, $sWord)
-       {
-               $sWordQuoted = getDBQuoted(trim($sWord));
-               $sSQL = "select *,levenshtein($sWordQuoted,word) from test_token ";
-               $sSQL .= "where (metaphone = dmetaphone($sWordQuoted) or metaphonealt = dmetaphone($sWordQuoted) or ";
-               $sSQL .= "metaphone = dmetaphone_alt($sWordQuoted) or metaphonealt = dmetaphone_alt($sWordQuoted)) ";
-               $sSQL .= "and len between length($sWordQuoted)-2 and length($sWordQuoted)+2 ";
-               $sSQL .= "and levenshtein($sWordQuoted,word) < 3 ";
-               $sSQL .= "order by levenshtein($sWordQuoted,word) asc, abs(len - length($sWordQuoted)) asc limit 20";
-               $aSimilar = $oDB->getAll($sSQL);
-               return $aSimilar;
-       }
-
-
        function geocodeReverse($fLat, $fLon, $iZoom=18)
        {
                $oDB =& getDB();
        function geocodeReverse($fLat, $fLon, $iZoom=18)
        {
                $oDB =& getDB();
                        $sSQL .= ' ORDER BY ST_distance('.$sPointSQL.', geometry) ASC limit 1';
                        //var_dump($sSQL);
                        $aPlace = $oDB->getRow($sSQL);
                        $sSQL .= ' ORDER BY ST_distance('.$sPointSQL.', geometry) ASC limit 1';
                        //var_dump($sSQL);
                        $aPlace = $oDB->getRow($sSQL);
-                       $iPlaceID = $aPlace['place_id'];
-                       if (PEAR::IsError($iPlaceID))
+                       if (PEAR::IsError($aPlace))
                        {
                        {
-                               var_Dump($sSQL, $iPlaceID);
+                               var_Dump($sSQL, $aPlace);
                                exit;
                        }
                                exit;
                        }
+                       $iPlaceID = $aPlace['place_id'];
                }
 
                // The point we found might be too small - use the address to find what it is a child of
                }
 
                // The point we found might be too small - use the address to find what it is a child of
                return $iPlaceID;
        }
 
                return $iPlaceID;
        }
 
-       function loadStructuredAddressElement(&$aStructuredQuery, &$iMinAddressRank, &$iMaxAddressRank, $aParams, $sKey, $iNewMinAddressRank, $iNewMaxAddressRank)
+       function addQuotes($s)
        {
        {
-               if (!isset($_GET[$sKey])) return false;
-               $sValue = trim($_GET[$sKey]);
-               if (!$sValue) return false;
-               $aStructuredQuery[$sKey] = $sValue;
-               if ($iMinAddressRank == 0 && $iMaxAddressRank == 30)
-               {
-                       $iMinAddressRank = $iNewMinAddressRank;
-                       $iMaxAddressRank = $iNewMaxAddressRank;
-               }
-               return true;
+               return "'".$s."'";
        }
        }