]> git.openstreetmap.org Git - nominatim.git/commitdiff
Merge remote-tracking branch 'upstream/master'
authorSarah Hoffmann <lonvia@denofr.de>
Sun, 17 Dec 2017 22:51:43 +0000 (23:51 +0100)
committerSarah Hoffmann <lonvia@denofr.de>
Sun, 17 Dec 2017 22:51:43 +0000 (23:51 +0100)
docs/Import-and-Update.md
lib/SearchDescription.php
sql/functions.sql
sql/words_from_search_name.sql [new file with mode: 0644]
test/bdd/db/import/linking.feature
utils/update.php
website/polygons.php

index fe95e8654ac1acbcb83408b57295a2cea043953d..ec451e8f813afe2f4f15d9c821adb02156cf0605 100644 (file)
@@ -68,6 +68,17 @@ import, for excerpts you can use less. Adapt to your available RAM to
 avoid swapping, never give more than 2/3 of RAM to osm2pgsql.
 
 
+Computing word frequency for search terms can improve the performance of
+forward geocoding in particular under high load as it helps Postgres' query
+planner to make the right decisions. To recompute word counts run:
+
+    ./utils/update.php --recompute-word-counts
+
+This will take a couple of hours for a full planet installation. You can
+also defer that step to a later point in time when you realise that
+performance becomes an issue. Just make sure that updates are stopped before
+running this function.
+
 Loading additional datasets
 ---------------------------
 
index 13775d65fd9c94c19e27a47f1ea64beb46f8f543..5431b3eb957907417d38f130a3dd91abeb6bfc6f 100644 (file)
@@ -262,7 +262,7 @@ class SearchDescription
 
                 $iOp = Operator::NEAR; // near == in for the moment
                 if ($aSearchTerm['operator'] == '') {
-                    if (sizeof($this->aName)) {
+                    if (sizeof($this->aName) || $this->oContext->isBoundedSearch()) {
                         $iOp = Operator::NAME;
                     }
                     $oSearch->iSearchRank += 2;
index e5e189a8f7766f9c114a60deec78bce0e0c9046a..70580408b73beb21319af1bcca22b26a91fd2ab9 100644 (file)
@@ -1355,7 +1355,7 @@ BEGIN
                 --DEBUG: RAISE WARNING 'waterway parent %, child %/%', NEW.osm_id, i, relation_members[i];
                 FOR linked_node_id IN SELECT place_id FROM placex
                   WHERE osm_type = 'W' and osm_id = substring(relation_members[i],2,200)::bigint
-                  and class = NEW.class and type = NEW.type
+                  and class = NEW.class and type in ('river', 'stream', 'canal', 'drain', 'ditch')
                   and ( relation_members[i+1] != 'side_stream' or NEW.name->'name' = name->'name')
                 LOOP
                   UPDATE placex SET linked_place_id = NEW.place_id WHERE place_id = linked_node_id;
diff --git a/sql/words_from_search_name.sql b/sql/words_from_search_name.sql
new file mode 100644 (file)
index 0000000..b7727dc
--- /dev/null
@@ -0,0 +1,11 @@
+DROP TABLE IF EXISTS word_frequencies;
+CREATE TABLE word_frequencies AS
+ SELECT unnest(name_vector) as id, count(*) FROM search_name GROUP BY id;
+
+CREATE INDEX idx_word_frequencies ON word_frequencies(id);
+
+UPDATE word SET search_name_count = count
+  FROM word_frequencies
+ WHERE word_token like ' %' and word_id = id;
+
+DROP TABLE word_frequencies;
index ecb1c9dff62fe7628b4e52e1a05118303c0d3ddb..ceb455865a776875a56b1c3e4fcbb315d17d4378 100644 (file)
@@ -40,11 +40,11 @@ Feature: Linking of places
     Scenario: Relations are not linked when in waterway relations
         Given the scene split-road
         And the places
-         | osm | class    | type  | name  | geometry |
-         | W1  | waterway | river | Rhein | :w-2 |
-         | W2  | waterway | river | Rhein | :w-3 |
-         | R1  | waterway | river | Rhein | :w-1 + :w-2 + :w-3 |
-         | R2  | waterway | river | Limmat| :w-4a |
+         | osm | class    | type   | name  | geometry |
+         | W1  | waterway | stream | Rhein | :w-2 |
+         | W2  | waterway | river  | Rhein | :w-3 |
+         | R1  | waterway | river  | Rhein | :w-1 + :w-2 + :w-3 |
+         | R2  | waterway | river  | Limmat| :w-4a |
         And the relations
          | id | members                          | tags+type |
          | 1  | R2                               | waterway  |
@@ -69,11 +69,11 @@ Feature: Linking of places
          | object | linked_place_id |
          | R1     | - |
 
-    Scenario: Waterways are not linked when waterway types don't match
+    Scenario: Waterways are not linked when the way type is not a river feature
         Given the scene split-road
         And the places
          | osm | class    | type     | name  | geometry |
-         | W1  | waterway | drain    | Rhein | :w-2 |
+         | W1  | waterway | lock     | Rhein | :w-2 |
          | R1  | waterway | river    | Rhein | :w-1 + :w-2 + :w-3 |
         And the relations
          | id | members               | tags+type |
index 006a4774fa0792edb79f2c8d0dbe245d8ed06efb..bb77e430d860a0cbb028d791945d23f5c2860ad6 100755 (executable)
@@ -33,6 +33,7 @@ $aCMDOptions
    array('index-instances', '', 0, 1, 1, 1, 'int', 'Number of indexing instances (threads)'),
 
    array('deduplicate', '', 0, 1, 0, 0, 'bool', 'Deduplicate tokens'),
+   array('recompute-word-counts', '', 0, 1, 0, 0, 'bool', 'Compute frequency of full-word search terms'),
    array('no-npi', '', 0, 1, 0, 0, 'bool', '(obsolete)'),
   );
 getCmdOpt($_SERVER['argv'], $aCMDOptions, $aResult, true, true);
@@ -238,6 +239,12 @@ if ($aResult['deduplicate']) {
     }
 }
 
+if ($aResult['recompute-word-counts']) {
+    info('Recompute frequency of full-word search terms');
+    $sTemplate = file_get_contents(CONST_BasePath.'/sql/words_from_search_name.sql');
+    runSQLScript($sTemplate, true, true);
+}
+
 if ($aResult['index']) {
     passthru(CONST_InstallPath.'/nominatim/nominatim -i -d '.$aDSNInfo['database'].' -P '.$aDSNInfo['port'].' -t '.$aResult['index-instances'].' -r '.$aResult['index-rank']);
 }
index 989c8f66d7c656c88351730cdf8d50ea47c053ed..b249ae03382fa476d5583938a8b7d0705b453395 100755 (executable)
@@ -9,7 +9,7 @@ ini_set('memory_limit', '200M');
 $oParams = new Nominatim\ParameterParser();
 
 $sOutputFormat = 'html';
-$iDays = $oParams->getInt('days', 1);
+$iDays = $oParams->getInt('days', false);
 $bReduced = $oParams->getBool('reduced', false);
 $sClass = $oParams->getString('class', false);
 
@@ -22,11 +22,20 @@ while ($iTotalBroken && !sizeof($aPolygons)) {
     $sSQL = 'select osm_type as "type",osm_id as "id",class as "key",type as "value",name->\'name\' as "name",';
     $sSQL .= 'country_code as "country",errormessage as "error message",updated';
     $sSQL .= ' from import_polygon_error';
-    $sSQL .= " where updated > 'now'::timestamp - '".$iDays." day'::interval";
-    $iDays++;
 
-    if ($bReduced) $sSQL .= " and errormessage like 'Area reduced%'";
-    if ($sClass) $sSQL .= " and class = '".pg_escape_string($sClass)."'";
+    $aWhere = array();
+    if ($iDays) {
+        $aWhere[] = "updated > 'now'::timestamp - '".$iDays." day'::interval";
+        $iDays++;
+    }
+
+    if ($bReduced) $aWhere[] = "errormessage like 'Area reduced%'";
+    if ($sClass) $sWhere[] = "class = '".pg_escape_string($sClass)."'";
+
+    if (sizeof($aWhere)) {
+        $sSQL .= ' where '.join(' and ', $aWhere);
+    }
+
     $sSQL .= ' order by updated desc limit 1000';
     $aPolygons = chksql($oDB->getAll($sSQL));
 }