]> git.openstreetmap.org Git - nominatim.git/commitdiff
Merge branch 'master' of http://github.com/twain47/Nominatim
authorSarah Hoffmann <lonvia@denofr.de>
Sun, 18 Mar 2012 17:23:11 +0000 (18:23 +0100)
committerSarah Hoffmann <lonvia@denofr.de>
Sun, 18 Mar 2012 17:23:11 +0000 (18:23 +0100)
1  2 
sql/functions.sql
website/reverse.php
website/search.php

diff --combined sql/functions.sql
index 84046d7ea88a47fcfaeaf294272df59b7b0f9c3e,a44fee9e9e78fb229694123fd45c6c9fb6635f6c..1411f300461b91707e4e82d52faa7a4849dd140e
@@@ -1108,7 -1108,7 +1108,7 @@@ BEGI
  --    RETURN NULL;
  --  END IF;
  
 -  RETURN NEW;  -- The following is not needed until doing diff updates, and slows the main index process down
 +--  RETURN NEW;  -- The following is not needed until doing diff updates, and slows the main index process down
  
    IF (ST_GeometryType(NEW.geometry) in ('ST_Polygon','ST_MultiPolygon') AND ST_IsValid(NEW.geometry)) THEN
      -- Performance: We just can't handle re-indexing for country level changes
  --    RAISE WARNING 'placex poly insert: % % % %',NEW.osm_type,NEW.osm_id,NEW.class,NEW.type;
  -- work around bug in postgis
        update placex set indexed_status = 2 where (ST_Contains(NEW.geometry, placex.geometry) OR ST_Intersects(NEW.geometry, placex.geometry)) 
-        AND rank_search > NEW.rank_search and indexed_status = 0 and ST_geometrytype(placex.geometry) = 'ST_Point';
+        AND rank_search > NEW.rank_search and indexed_status = 0 and ST_geometrytype(placex.geometry) = 'ST_Point' and (rank_search < 28 or name is not null);
        update placex set indexed_status = 2 where (ST_Contains(NEW.geometry, placex.geometry) OR ST_Intersects(NEW.geometry, placex.geometry)) 
-        AND rank_search > NEW.rank_search and indexed_status = 0 and ST_geometrytype(placex.geometry) != 'ST_Point';
+        AND rank_search > NEW.rank_search and indexed_status = 0 and ST_geometrytype(placex.geometry) != 'ST_Point' and (rank_search < 28 or name is not null);
      END IF;
    ELSE
      -- mark nearby items for re-indexing, where 'nearby' depends on the features rank_search and is a complete guess :(
      END IF;
      IF diameter > 0 THEN
  --      RAISE WARNING 'placex point insert: % % % % %',NEW.osm_type,NEW.osm_id,NEW.class,NEW.type,diameter;
-       update placex set indexed_status = 2 where indexed_status = 0 and rank_search > NEW.rank_search and ST_DWithin(placex.geometry, NEW.geometry, diameter);
+       update placex set indexed_status = 2 where indexed_status = 0 and rank_search > NEW.rank_search and ST_DWithin(placex.geometry, NEW.geometry, diameter) and (rank_search < 28 or name is not null);
      END IF;
  
    END IF;
@@@ -1792,12 -1792,12 +1792,12 @@@ BEGI
        update placex set indexed_status = 2 where indexed_status = 0 and 
            (ST_Contains(NEW.geometry, placex.geometry) OR ST_Intersects(NEW.geometry, placex.geometry))
            AND NOT (ST_Contains(existinggeometry, placex.geometry) OR ST_Intersects(existinggeometry, placex.geometry))
-           AND rank_search > existingplacex.rank_search;
+           AND rank_search > existingplacex.rank_search AND (rank_search < 28 or name is not null);
  
        update placex set indexed_status = 2 where indexed_status = 0 and 
            (ST_Contains(existinggeometry, placex.geometry) OR ST_Intersects(existinggeometry, placex.geometry))
            AND NOT (ST_Contains(NEW.geometry, placex.geometry) OR ST_Intersects(NEW.geometry, placex.geometry))
-           AND rank_search > existingplacex.rank_search;
+           AND rank_search > existingplacex.rank_search AND (rank_search < 28 or name is not null);
  
      END IF;
  
  
        IF st_area(NEW.geometry) < 0.5 THEN
          UPDATE placex set indexed_status = 2 from place_addressline where address_place_id = existingplacex.place_id 
-           and placex.place_id = place_addressline.place_id and indexed_status = 0;
+           and placex.place_id = place_addressline.place_id and indexed_status = 0
+           and (rank_search < 28 or name is not null);
        END IF;
  
      END IF;
@@@ -2393,13 -2394,6 +2394,6 @@@ END
  $$
  LANGUAGE plpgsql;
  
- CREATE AGGREGATE array_agg(INT[])
- (
-     sfunc = array_cat,
-     stype = INT[],
-     initcond = '{}'
- );
  CREATE OR REPLACE FUNCTION tigger_create_interpolation(linegeo GEOMETRY, in_startnumber INTEGER, 
    in_endnumber INTEGER, interpolationtype TEXT, 
    in_street TEXT, in_isin TEXT, in_postcode TEXT) RETURNS INTEGER
diff --combined website/reverse.php
index b050484d0c052b54ef964cceebd6ea11c181be86,d9ecc09efc83d022cfb3aa4955357bd12b1eee9b..ed7090e264ba68e871a482534a6bc4b4f89ddc7b
@@@ -2,21 -2,7 +2,21 @@@
        require_once(dirname(dirname(__FILE__)).'/lib/init-website.php');
        require_once(CONST_BasePath.'/lib/log.php');
  
 -      $oDB =& getDB();
 +    if (preg_match(CONST_BlockedUserAgents, $_SERVER["HTTP_USER_AGENT"]) > 0)
 +    {
 +        $fLoadAvg = getLoadAverage();
 +        if ($fLoadAvg >= CONST_BlockReverseMaxLoad) {
 +            header('HTTP/1.0 403 Forbidden');
 +            header('Content-type: text/html; charset=utf-8');
 +              echo "<html><body><h1>App temporarily blocked</h1>";
 +            echo "Your application has been temporarily blocked from the OpenStreetMap Nominatim ";
 +            echo "geolocation service due to high server load.";
 +            echo "\n</body></html>\n";
 +            exit;
 +        }
 +
 +    }
 +
  
          if (strpos(CONST_BulkUserIPs, ','.$_SERVER["REMOTE_ADDR"].',') !== false)
          {
                  }
          }
  
 +        $oDB =& getDB();
          ini_set('memory_limit', '200M');
  
          // Format for output
 -      $sOutputFormat = 'xml';
 +        $sOutputFormat = 'xml';
          if (isset($_GET['format']) && ($_GET['format'] == 'xml' || $_GET['format'] == 'json' || $_GET['format'] == 'jsonv2'))
          {
                  $sOutputFormat = $_GET['format'];
                        $iPlaceID = $aPlace['place_id'];
                        if (PEAR::IsError($iPlaceID))
                        {
-                               var_Dump($sSQL, $iPlaceID); 
-                               exit;
+                               failInternalError("Could not determine closest place.", $sSQL, $iPlaceID); 
                        }
                }
  
                        $iPlaceID = $oDB->getOne($sSQL);
                        if (PEAR::IsError($iPlaceID))
                        {
-                               var_Dump($sSQL, $iPlaceID); 
-                               exit;
+                               failInternalError("Could not get parent for place.", $sSQL, $iPlaceID); 
                        }
  
                        if ($iPlaceID && $aPlace['place_id'] && $iMaxRank < 28)
                                $iPlaceID = $oDB->getOne($sSQL);
                                if (PEAR::IsError($iPlaceID))
                                {
-                                       var_Dump($sSQL, $iPlaceID); 
-                                       exit;
+                                       failInternalError("Could not get larger parent for place.", $sSQL, $iPlaceID); 
                                }
                        }
                        if (!$iPlaceID)
diff --combined website/search.php
index fd91f31daff2831f349c0b5f5ce8725c306b1436,50d009e1a75e46e2c71362e63714a007895eed98..a049f07e6c4b5f7702f4148aa58fbeb74c510577
                        $sViewboxSmallSQL = $oDB->getOne($sSQL);
                        if (PEAR::isError($sViewboxSmallSQL))
                        {
-                               var_dump($sViewboxSmallSQL);
-                               exit;
+                               failInternalError("Could not get small viewbox.", $sSQL, $sViewboxSmallSQL);
                        }
                        $sViewboxSmallSQL = "'".$sViewboxSmallSQL."'::geometry";
  
                        $sViewboxLargeSQL = $oDB->getOne($sSQL);
                        if (PEAR::isError($sViewboxLargeSQL))
                        {
-                               var_dump($sViewboxLargeSQL);
-                               exit;
+                               failInternalError("Could not get large viewbox.", $sSQL, $sViewboxLargeSQL);
                        }
                        $sViewboxLargeSQL = "'".$sViewboxLargeSQL."'::geometry";
                }
                        // Check which tokens we have, get the ID numbers                       
                        $sSQL = 'select word_id,word_token, word, class, type, location, country_code, operator';
                        $sSQL .= ' from word where word_token in ('.join(',',array_map("getDBQuoted",$aTokens)).')';
 -                      $sSQL .= ' and (class is null or class not in (\'highway\'))';
 +                      // HACK WARNING
 +                      // (mis)using search_name_count to exclude words that return too many
 +                      // search results. saerch_name_count is currently set to 1 by hand
 +                      // because there is no fast way to extract this count from a live database. 
 +                      $sSQL .= ' and search_name_count = 0';
 +//                    $sSQL .= ' and (class is null or class not in (\'highway\'))';
  //                    $sSQL .= ' group by word_token, word, class, type, location, country_code';
  
                        if (CONST_Debug) var_Dump($sSQL);
                                $aDatabaseWords = array();
                        if (PEAR::IsError($aDatabaseWords))
                        {
-                               var_dump($sSQL, $aDatabaseWords);
-                               exit;
+                               failInternalError("Could not get word tokens.", $sSQL, $aDatabaseWords);
                        }
                        $aPossibleMainWordIDs = array();
                        foreach($aDatabaseWords as $aToken)
                                                                        $sSQL .= " limit ".$iLimit;
  
                                                                if (CONST_Debug) var_dump($sSQL);
 +                                                              $iStartTime = time();
                                                                $aViewBoxPlaceIDs = $oDB->getAll($sSQL);
                                                                if (PEAR::IsError($aViewBoxPlaceIDs))
                                                                {
-                                                                       var_dump($sSQL, $aViewBoxPlaceIDs);                                     
-                                                                       exit;
+                                                                       failInternalError("Could not get places for search terms.", $sSQL, $aViewBoxPlaceIDs);
                                                                }
 +                                                              if (time() - $iStartTime > 60) {
 +                                                                      file_put_contents(CONST_BasePath.'/log/long_queries.log', date('Y-m-d H:i:s', $iStartTime).' '.$sSQL."\n", FILE_APPEND);
 +                                                              }
 +
  //var_dump($aViewBoxPlaceIDs);
                                                                // Did we have an viewbox matches?
                                                                $aPlaceIDs = array();
  
                                                if (PEAR::IsError($aPlaceIDs))
                                                {
-                                                       var_dump($sSQL, $aPlaceIDs);                                    
-                                                       exit;
+                                                       failInternalError("Could not get place IDs from tokens." ,$sSQL, $aPlaceIDs);
                                                }
  
                                                if (CONST_Debug) var_Dump($aPlaceIDs);
  
                                        if (PEAR::IsError($aSearchResults))
                                        {
-                                               var_dump($sSQL, $aSearchResults);                                       
-                                               exit;
+                                               failInternalError("Could not get details for place.", $sSQL, $aSearchResults);
                                        }
                                }
                        } // end if ($sQuery)
  
                                        if (PEAR::IsError($aSearchResults))
                                        {
-                                               var_dump($sSQL, $aSearchResults);                                       
-                                               exit;
+                         failInternalError("Could not get details for place (near).", $sSQL, $aSearchResults);
                                        }
                                }
                        }
                        $aPointPolygon = $oDB->getRow($sSQL);
                        if (PEAR::IsError($aPointPolygon))
                        {
-                               var_dump($sSQL, $aPointPolygon);
-                               exit;
+                               failInternalError("Could not get outline.", $sSQL, $aPointPolygon);
                        }
                        if ($aPointPolygon['place_id'])
                        {