@@ -159,12 +159,17 @@ int main(int argc, char *argv[])
159
159
160
160
const std::string base_query
161
161
= R"SQL(
162
- select pl.place_id, linked_place_id, parent_place_resolved as parent_place_id, country_code, class, type,
162
+ select pl.place_id, linked_place_id, parent_place_resolved as parent_place_id, pl. country_code, class, type,
163
163
hstore_to_json(name) as name, hstore_to_json(extratags) as extra,
164
164
COALESCE(address->'housenumber',housenumber) AS housenumber,
165
- postcode, ST_X(centroid) as longitude, ST_Y(centroid) as latitude,
165
+ postcode, ST_X(pl.centroid) as longitude, ST_Y(pl.centroid) as latitude,
166
+ CASE
167
+ WHEN sname.importance IS NOT NULL THEN (100*(1-sname.importance))::int
168
+ ELSE 100 + pl.rank_search
169
+ END AS search_rank,
166
170
osm_type, osm_id
167
171
from placex pl
172
+ left join search_name as sname on sname.place_id=pl.place_id
168
173
left join lateral
169
174
(select address_place_id from place_addressline a where a.place_id=pl.place_id
170
175
order by cached_rank_address desc, fromarea desc, distance asc limit 1) as a on true
@@ -238,6 +243,7 @@ select place_id as parent_place_resolved from prec where linked_place_id is null
238
243
select pc.place_id, NULL as linked_place_id, parent_place_resolved as parent_place_id, country_code, 'postal' as class, 'code' as type,
239
244
NULL as name, NULL as extra, NULL as housenumber,
240
245
postcode, ST_X(geometry) as longitude, ST_Y(geometry) as latitude,
246
+ 100 AS search_rank,
241
247
NULL as osm_type, NULL as osm_id
242
248
from location_postcode pc
243
249
left join lateral
@@ -306,7 +312,7 @@ select place_id as parent_place_resolved from prec where linked_place_id is null
306
312
for (std::string country : hierarchy.get_root_countries ())
307
313
{
308
314
for (auto row : txn.exec_params (
309
- base_query + " where rank_address = 4 and country_code = $1 limit 1" , country))
315
+ base_query + " where pl. rank_address = 4 and pl. country_code = $1 limit 1" , country))
310
316
{
311
317
hindex id = row[" place_id" ].as <hindex>(0 );
312
318
if (!hierarchy.has_item (id))
@@ -364,6 +370,7 @@ select place_id as parent_place_resolved from prec where linked_place_id is null
364
370
db.execute (" CREATE " TEMPORARY " TABLE object_primary_tmp ("
365
371
" id INTEGER PRIMARY KEY AUTOINCREMENT, postgres_id INTEGER, name TEXT, name_extra "
366
372
" TEXT, name_en TEXT, phone TEXT, postal_code TEXT, website TEXT, parent INTEGER, "
373
+ " search_rank INTEGER, "
367
374
" latitude REAL, longitude REAL)" );
368
375
db.execute (" CREATE " TEMPORARY " TABLE object_type_tmp (prim_id INTEGER, type TEXT NOT NULL, "
369
376
" FOREIGN KEY (prim_id) REFERENCES objects_primary_tmp(id))" );
@@ -385,13 +392,14 @@ select place_id as parent_place_resolved from prec where linked_place_id is null
385
392
db.execute (" CREATE " TEMPORARY
386
393
" TABLE object_primary_tmp2 (id INTEGER PRIMARY KEY AUTOINCREMENT, "
387
394
" name TEXT, name_extra TEXT, name_en TEXT, phone TEXT, postal_code TEXT, website "
388
- " TEXT, parent INTEGER, type_id INTEGER, latitude REAL, longitude REAL, boxstr TEXT, "
395
+ " TEXT, parent INTEGER, type_id INTEGER, latitude REAL, longitude REAL, "
396
+ " search_rank INTEGER, boxstr TEXT, "
389
397
" FOREIGN KEY (type_id) REFERENCES type(id))" );
390
398
391
399
db.execute (" INSERT INTO object_primary_tmp2 (id, name, name_extra, name_en, phone, postal_code, "
392
- " website, parent, type_id, latitude, longitude, boxstr) "
400
+ " website, parent, type_id, latitude, longitude, search_rank, boxstr) "
393
401
" SELECT p.id, p.name, p.name_extra, p.name_en, p.phone, p.postal_code, p.website, "
394
- " p.parent, type.id, p.latitude, p.longitude, "
402
+ " p.parent, type.id, p.latitude, p.longitude, p.search_rank, "
395
403
// LINE BELOW DETERMINES ROUNDING USED FOR BOXES
396
404
" CAST(CAST(p.latitude*100 AS INTEGER) AS TEXT) || ',' || CAST(CAST(p.longitude*100 AS "
397
405
" INTEGER) AS TEXT) "
@@ -404,13 +412,15 @@ select place_id as parent_place_resolved from prec where linked_place_id is null
404
412
405
413
db.execute (" CREATE TABLE object_primary (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, "
406
414
" name_extra TEXT, name_en TEXT, phone TEXT, postal_code TEXT, website TEXT, "
407
- " parent INTEGER, type_id INTEGER, latitude REAL, longitude REAL, box_id INTEGER, "
415
+ " parent INTEGER, type_id INTEGER, latitude REAL, longitude REAL, search_rank INTEGER, "
416
+ " box_id INTEGER, "
408
417
" FOREIGN KEY (type_id) REFERENCES type(id))" );
409
418
db.execute (
410
419
" INSERT INTO object_primary (id, name, name_extra, name_en, phone, postal_code, website, "
411
- " parent, type_id, latitude, longitude, box_id) "
420
+ " parent, type_id, latitude, longitude, search_rank, box_id) "
412
421
" SELECT o.id, name, name_extra, name_en, phone, postal_code, website, parent, type_id, "
413
- " latitude, longitude, b.id FROM object_primary_tmp2 o JOIN boxids b ON o.boxstr=b.boxstr" );
422
+ " latitude, longitude, search_rank, b.id FROM object_primary_tmp2 o JOIN boxids b ON "
423
+ " o.boxstr=b.boxstr" );
414
424
415
425
db.execute (" DROP INDEX IF EXISTS idx_object_primary_box" );
416
426
db.execute (" CREATE INDEX idx_object_primary_box ON object_primary (box_id)" );
0 commit comments