]> git.openstreetmap.org Git - nominatim.git/blobdiff - lib/setup/SetupClass.php
Add reverse-only parameter to setup
[nominatim.git] / lib / setup / SetupClass.php
index dde834f7d100766fe740aa9ec5aa68772a204b0b..f03085f8c39159c11f9a94607768f285286cec3c 100755 (executable)
@@ -230,7 +230,7 @@ class SetupFunctions
         $this->createSqlFunctions();
     }
 
         $this->createSqlFunctions();
     }
 
-    public function createTables()
+    public function createTables($bReverseOnly = false)
     {
         info('Create Tables');
 
     {
         info('Create Tables');
 
@@ -268,6 +268,10 @@ class SetupFunctions
         );
 
         $this->pgsqlRunScript($sTemplate, false);
         );
 
         $this->pgsqlRunScript($sTemplate, false);
+
+        if ($bReverseOnly) {
+            $this->pgExec('DROP TABLE search_name');
+        }
     }
 
     public function createPartitionTables()
     }
 
     public function createPartitionTables()
@@ -356,8 +360,10 @@ class SetupFunctions
         echo '.';
         $this->pgExec('TRUNCATE location_area');
         echo '.';
         echo '.';
         $this->pgExec('TRUNCATE location_area');
         echo '.';
-        $this->pgExec('TRUNCATE search_name');
-        echo '.';
+        if (!$this->dbReverseOnly()) {
+            $this->pgExec('TRUNCATE search_name');
+            echo '.';
+        }
         $this->pgExec('TRUNCATE search_name_blank');
         echo '.';
         $this->pgExec('DROP SEQUENCE seq_place');
         $this->pgExec('TRUNCATE search_name_blank');
         echo '.';
         $this->pgExec('DROP SEQUENCE seq_place');
@@ -608,6 +614,9 @@ class SetupFunctions
         info('Create Search indices');
 
         $sTemplate = file_get_contents(CONST_BasePath.'/sql/indices.src.sql');
         info('Create Search indices');
 
         $sTemplate = file_get_contents(CONST_BasePath.'/sql/indices.src.sql');
+        if (!$this->dbReverseOnly()) {
+            $sTemplate .= file_get_contents(CONST_BasePath.'/sql/indices_search.src.sql');
+        }
         $sTemplate = str_replace('{www-user}', CONST_Database_Web_User, $sTemplate);
         $sTemplate = $this->replaceTablespace(
             '{ts:address-index}',
         $sTemplate = str_replace('{www-user}', CONST_Database_Web_User, $sTemplate);
         $sTemplate = $this->replaceTablespace(
             '{ts:address-index}',
@@ -748,6 +757,10 @@ class SetupFunctions
         if (!CONST_Use_Aux_Location_data) {
             $sTemplate = str_replace('-- %NOAUXDATA% ', '', $sTemplate);
         }
         if (!CONST_Use_Aux_Location_data) {
             $sTemplate = str_replace('-- %NOAUXDATA% ', '', $sTemplate);
         }
+
+        $sReverseOnly = $this->dbReverseOnly() ? 'true' : 'false';
+        $sTemplate = str_replace('%REVERSE-ONLY%', $sReverseOnly, $sTemplate);
+
         $this->pgsqlRunScript($sTemplate);
     }
 
         $this->pgsqlRunScript($sTemplate);
     }
 
@@ -861,4 +874,15 @@ class SetupFunctions
             fail(pg_last_error($this->oDB->connection));
         }
     }
             fail(pg_last_error($this->oDB->connection));
         }
     }
+
+    /**
+     * Check if the database is in reverse-only mode.
+     *
+     * @return True if there is no search_name table and infrastructure.
+     */
+    private function dbReverseOnly()
+    {
+        $sSQL = "SELECT count(*) FROM pg_tables WHERE tablename = 'search_name'";
+        return !(chksql($this->oDB->getOne($sSQL)));
+    }
 }
 }