]> git.openstreetmap.org Git - nominatim.git/blobdiff - nominatim/index.c
Use check_import_finished in test suite, document
[nominatim.git] / nominatim / index.c
index ca301f45b305ea5826f214fb90f5504b7ae00ed1..bb553f7e7e56e28a87ebd24af9aca10c101b97dd 100644 (file)
@@ -140,13 +140,7 @@ struct index_thread_data * thread_data, const char *structuredoutputfile)
 
             // Get all the place_id's for this sector
             paramRank = PGint32(rank);
-            paramValues[0] = (char *)&paramRank;
-            paramLengths[0] = sizeof(paramRank);
-            paramFormats[0] = 1;
             paramSector = PGint32(sector);
-            paramValues[1] = (char *)&paramSector;
-            paramLengths[1] = sizeof(paramSector);
-            paramFormats[1] = 1;
             if (rankTotalTuples-rankCountTuples < num_threads*1000)
             {
                 // no sectors
@@ -156,6 +150,9 @@ struct index_thread_data * thread_data, const char *structuredoutputfile)
                 }
                 else
                 {
+                    paramValues[0] = (char *)&paramRank;
+                    paramLengths[0] = sizeof(paramRank);
+                    paramFormats[0] = 1;
                     iResult = PQsendQueryPrepared(conn, "index_nosector_places", 1, paramValues, paramLengths, paramFormats, 1);
                 }
             }
@@ -163,11 +160,19 @@ struct index_thread_data * thread_data, const char *structuredoutputfile)
             {
                 if (interpolation)
                 {
-                                       iResult = PQsendQueryPrepared(conn, "index_sector_places_osmline", 1, paramValues, paramLengths, paramFormats, 1);
-
+                    iResult = PQsendQueryPrepared(conn, "index_sector_places_osmline", 1, paramValues, paramLengths, paramFormats, 1);
+                    paramValues[0] = (char *)&paramSector;
+                    paramLengths[0] = sizeof(paramSector);
+                    paramFormats[0] = 1;
                 }
                 else
                 {
+                    paramValues[0] = (char *)&paramRank;
+                    paramLengths[0] = sizeof(paramRank);
+                    paramFormats[0] = 1;
+                    paramValues[1] = (char *)&paramSector;
+                    paramLengths[1] = sizeof(paramSector);
+                    paramFormats[1] = 1;
                     iResult = PQsendQueryPrepared(conn, "index_sector_places", 2, paramValues, paramLengths, paramFormats, 1);
                 }
             }
@@ -213,10 +218,18 @@ struct index_thread_data * thread_data, const char *structuredoutputfile)
                     usleep(1000);
 
                     // Aim for one update per second
-                    if (sleepcount++ > 500)
+                    if (sleepcount++ > 1000)
                     {
                         rankPerSecond = ((float)rankCountTuples + (float)count) / MAX(difftime(time(0), rankStartTime),1);
-                        fprintf(stderr, "  Done %i in %i @ %f per second - Rank %i ETA (seconds): %f\n", (rankCountTuples + count), (int)(difftime(time(0), rankStartTime)), rankPerSecond, rank, ((float)(rankTotalTuples - (rankCountTuples + count)))/rankPerSecond);
+                        if(interpolation)
+                        {
+                            fprintf(stderr, "  Done %i in %i @ %f per second - Interpolation lines ETA (seconds): %f\n", (rankCountTuples + count), (int)(difftime(time(0), rankStartTime)), rankPerSecond, ((float)(rankTotalTuples - (rankCountTuples + count)))/rankPerSecond);
+                        }
+                        else
+                        {
+                            fprintf(stderr, "  Done %i in %i @ %f per second - Rank %i ETA (seconds): %f\n", (rankCountTuples + count), (int)(difftime(time(0), rankStartTime)), rankPerSecond, rank, ((float)(rankTotalTuples - (rankCountTuples + count)))/rankPerSecond);
+                        }
+                        
                         sleepcount = 0;
                     }
                 }
@@ -249,13 +262,16 @@ struct index_thread_data * thread_data, const char *structuredoutputfile)
 
 void nominatim_index(int rank_min, int rank_max, int num_threads, const char *conninfo, const char *structuredoutputfile)
 {
-    struct index_thread_data * thread_data;
+    struct index_thread_data *thread_data;
 
     PGconn *conn;
-    PGresult * res;
+    PGresult *res;
+    int num_rows = 0, status_code = 0;
+    int db_has_locale = 0;
+    char *result_string = NULL;
 
     int rank;
-    
+
     int i;
 
     xmlTextWriterPtr writer;
@@ -270,6 +286,23 @@ void nominatim_index(int rank_min, int rank_max, int num_threads, const char *co
         exit(EXIT_FAILURE);
     }
 
+    res = PQexec(conn, "SHOW lc_messages");
+    status_code = PQresultStatus(res);
+    if (status_code != PGRES_TUPLES_OK && status_code != PGRES_SINGLE_TUPLE) {
+        fprintf(stderr, "Failed determining database locale: %s\n", PQerrorMessage(conn));
+        exit(EXIT_FAILURE);
+    }
+    num_rows = PQntuples(res);
+    if (num_rows > 0)
+    {
+        result_string = PQgetvalue(res, 0, 0);
+        if (result_string && (strlen(result_string) > 0) && (strcasecmp(result_string, "C") != 0))
+        {
+            // non-default locale if the result exists, is non-empty, and is not "C"
+            db_has_locale = 1;
+        }
+    }
+
     pg_prepare_params[0] = PG_OID_INT4;
     res = PQprepare(conn, "index_sectors",
                     "select geometry_sector,count(*) from placex where rank_search = $1 and indexed_status > 0 group by geometry_sector order by geometry_sector",
@@ -363,7 +396,7 @@ void nominatim_index(int rank_min, int rank_max, int num_threads, const char *co
                         1, pg_prepare_params);
         if (PQresultStatus(res) != PGRES_COMMAND_OK)
         {
-            fprintf(stderr, "Failed preparing index_placex: %s\n", PQerrorMessage(conn));
+            fprintf(stderr, "Failed preparing index_placex: %s\n", PQerrorMessage(thread_data[i].conn));
             exit(EXIT_FAILURE);
         }
         PQclear(res);
@@ -374,23 +407,25 @@ void nominatim_index(int rank_min, int rank_max, int num_threads, const char *co
                         1, pg_prepare_params);
         if (PQresultStatus(res) != PGRES_COMMAND_OK)
         {
-            fprintf(stderr, "Failed preparing index_osmline: %s\n", PQerrorMessage(conn));
+            fprintf(stderr, "Failed preparing index_osmline: %s\n", PQerrorMessage(thread_data[i].conn));
             exit(EXIT_FAILURE);
         }
         PQclear(res);
 
-        /*res = PQexec(thread_data[i].conn, "set enable_seqscan = false");
-        if (PQresultStatus(res) != PGRES_COMMAND_OK)
+        if (db_has_locale)
         {
-            fprintf(stderr, "Failed disabling sequential scan: %s\n", PQerrorMessage(conn));
-            exit(EXIT_FAILURE);
+            // Make sure the error message is not localized as we parse it later.
+            res = PQexec(thread_data[i].conn, "SET lc_messages TO 'C'");
+            if (PQresultStatus(res) != PGRES_COMMAND_OK)
+            {
+                fprintf(stderr, "Failed to set langauge: %s\n", PQerrorMessage(thread_data[i].conn));
+                exit(EXIT_FAILURE);
+            }
+            PQclear(res);
         }
-        PQclear(res);*/
-
         nominatim_exportCreatePreparedQueries(thread_data[i].conn);
     }
 
-
     fprintf(stderr, "Starting indexing rank (%i to %i) using %i threads\n", rank_min, rank_max, num_threads);
 
     for (rank = rank_min; rank <= rank_max; rank++)
@@ -424,9 +459,9 @@ void *nominatim_indexThread(void * thread_data_in)
     uint64_t    paramPlaceID;
     uint64_t    place_id;
     time_t      updateStartTime;
-    uint        table;
+    unsigned    table;
     
-    table = (uint)(thread_data->table);
+    table = thread_data->table;
 
     while (1)
     {