@hebcal/geo-sqlite 4.4.1 → 4.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +78 -51
- package/dist/index.mjs +78 -51
- package/package.json +8 -8
- package/zips-dummy.sql +4 -1
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! @hebcal/geo-sqlite v4.
|
|
1
|
+
/*! @hebcal/geo-sqlite v4.5.0 */
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
4
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
@@ -29,6 +29,7 @@ const GEONAME_SQL = `SELECT
|
|
|
29
29
|
a.asciiname as admin1,
|
|
30
30
|
g.latitude as latitude,
|
|
31
31
|
g.longitude as longitude,
|
|
32
|
+
g.population as population,
|
|
32
33
|
g.timezone as timezone
|
|
33
34
|
FROM geoname g
|
|
34
35
|
LEFT JOIN country c on g.country = c.iso
|
|
@@ -44,33 +45,29 @@ const GEONAME_ALL_SQL = `SELECT
|
|
|
44
45
|
a.asciiname as admin1,
|
|
45
46
|
g.latitude as latitude,
|
|
46
47
|
g.longitude as longitude,
|
|
48
|
+
g.population as population,
|
|
47
49
|
g.timezone as timezone
|
|
48
50
|
FROM geoname g
|
|
49
51
|
LEFT JOIN country c on g.country = c.iso
|
|
50
52
|
LEFT JOIN admin1 a on g.country||'.'||g.admin1 = a.key
|
|
51
53
|
`;
|
|
52
|
-
const ZIPCODE_SQL = `SELECT CityMixedCase,State,Latitude,Longitude,TimeZone,DayLightSaving
|
|
54
|
+
const ZIPCODE_SQL = `SELECT ZipCode,CityMixedCase,State,Latitude,Longitude,TimeZone,DayLightSaving,Population
|
|
53
55
|
FROM ZIPCodes_Primary WHERE ZipCode = ?`;
|
|
54
|
-
const ZIPCODE_ALL_SQL = `SELECT ZipCode,CityMixedCase,State,Latitude,Longitude,TimeZone,DayLightSaving
|
|
56
|
+
const ZIPCODE_ALL_SQL = `SELECT ZipCode,CityMixedCase,State,Latitude,Longitude,TimeZone,DayLightSaving,Population
|
|
55
57
|
FROM ZIPCodes_Primary`;
|
|
56
58
|
const ZIP_COMPLETE_SQL = `SELECT ZipCode,CityMixedCase,State,Latitude,Longitude,TimeZone,DayLightSaving,Population
|
|
57
59
|
FROM ZIPCodes_Primary
|
|
58
60
|
WHERE ZipCode LIKE ?
|
|
59
61
|
ORDER BY Population DESC
|
|
60
62
|
LIMIT 10`;
|
|
61
|
-
const ZIP_FULLTEXT_COMPLETE_SQL = `SELECT ZipCode
|
|
62
|
-
FROM
|
|
63
|
-
WHERE
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
const GEONAME_COMPLETE_SQL = `SELECT geonameid, asciiname, admin1, country,
|
|
67
|
-
population, latitude, longitude, timezone,
|
|
68
|
-
((sqrt(population)/40) + (-30 * rank)) as myrank
|
|
63
|
+
const ZIP_FULLTEXT_COMPLETE_SQL = `SELECT ZipCode
|
|
64
|
+
FROM ZIPCodes_CityFullText5
|
|
65
|
+
WHERE ZIPCodes_CityFullText5 MATCH ?
|
|
66
|
+
LIMIT 20`;
|
|
67
|
+
const GEONAME_COMPLETE_SQL = `SELECT geonameid
|
|
69
68
|
FROM geoname_fulltext
|
|
70
69
|
WHERE geoname_fulltext MATCH ?
|
|
71
|
-
|
|
72
|
-
ORDER BY myrank DESC
|
|
73
|
-
LIMIT 15`;
|
|
70
|
+
LIMIT 20`;
|
|
74
71
|
const stateNames = {
|
|
75
72
|
'AK': 'Alaska',
|
|
76
73
|
'AL': 'Alabama',
|
|
@@ -226,6 +223,7 @@ class GeoDb {
|
|
|
226
223
|
location.stateName = stateNames[location.state];
|
|
227
224
|
location.geo = 'zip';
|
|
228
225
|
location.zip = zip;
|
|
226
|
+
location.population = result.Population;
|
|
229
227
|
return location;
|
|
230
228
|
}
|
|
231
229
|
/**
|
|
@@ -263,13 +261,9 @@ class GeoDb {
|
|
|
263
261
|
const admin1 = result.admin1 || '';
|
|
264
262
|
const cityDescr = core.Location.geonameCityDescr(result.name, admin1, country);
|
|
265
263
|
const location = new core.Location(result.latitude, result.longitude, result.cc == 'IL', result.timezone, cityDescr, result.cc, geonameid);
|
|
266
|
-
|
|
267
|
-
if (result.asciiname !== result.name) {
|
|
268
|
-
location.asciiname = result.asciiname;
|
|
269
|
-
}
|
|
270
|
-
|
|
271
264
|
location.geo = 'geoname';
|
|
272
265
|
location.geonameid = geonameid;
|
|
266
|
+
location.asciiname = result.asciiname;
|
|
273
267
|
|
|
274
268
|
if (admin1) {
|
|
275
269
|
location.admin1 = admin1;
|
|
@@ -279,6 +273,10 @@ class GeoDb {
|
|
|
279
273
|
location.jersualem = true;
|
|
280
274
|
}
|
|
281
275
|
|
|
276
|
+
if (result.population) {
|
|
277
|
+
location.population = result.population;
|
|
278
|
+
}
|
|
279
|
+
|
|
282
280
|
return location;
|
|
283
281
|
}
|
|
284
282
|
/**
|
|
@@ -356,25 +354,42 @@ class GeoDb {
|
|
|
356
354
|
}
|
|
357
355
|
|
|
358
356
|
qraw = qraw.replace(/\"/g, '""');
|
|
359
|
-
const
|
|
357
|
+
const geoRows0 = this.geonamesCompStmt.all(`{longname} : "${qraw}" *`);
|
|
358
|
+
const ids = new Set();
|
|
359
|
+
const geoRows = [];
|
|
360
|
+
|
|
361
|
+
for (const row of geoRows0) {
|
|
362
|
+
const id = row.geonameid;
|
|
363
|
+
|
|
364
|
+
if (!ids.has(id)) {
|
|
365
|
+
ids.add(id);
|
|
366
|
+
geoRows.push(row);
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
|
|
360
370
|
const geoMatches = geoRows.map(res => {
|
|
361
|
-
const
|
|
362
|
-
const
|
|
363
|
-
const
|
|
371
|
+
const loc = this.lookupGeoname(res.geonameid);
|
|
372
|
+
const country = this.countryNames.get(loc.getCountryCode()) || '';
|
|
373
|
+
const admin1 = loc.admin1 || '';
|
|
364
374
|
const obj = {
|
|
365
375
|
id: res.geonameid,
|
|
366
|
-
value:
|
|
367
|
-
asciiname: res.asciiname,
|
|
376
|
+
value: loc.name,
|
|
368
377
|
admin1,
|
|
369
378
|
country,
|
|
370
|
-
latitude:
|
|
371
|
-
longitude:
|
|
372
|
-
timezone:
|
|
373
|
-
|
|
374
|
-
geo: 'geoname',
|
|
375
|
-
rank: rank
|
|
379
|
+
latitude: loc.latitude,
|
|
380
|
+
longitude: loc.longitude,
|
|
381
|
+
timezone: loc.getTzid(),
|
|
382
|
+
geo: 'geoname'
|
|
376
383
|
};
|
|
377
384
|
|
|
385
|
+
if (loc.population) {
|
|
386
|
+
obj.population = loc.population;
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
if (loc.asciiname) {
|
|
390
|
+
obj.asciiname = loc.asciiname;
|
|
391
|
+
}
|
|
392
|
+
|
|
378
393
|
if (country) {
|
|
379
394
|
obj.country = country;
|
|
380
395
|
}
|
|
@@ -390,8 +405,24 @@ class GeoDb {
|
|
|
390
405
|
this.zipFulltextCompStmt = this.zipsDb.prepare(ZIP_FULLTEXT_COMPLETE_SQL);
|
|
391
406
|
}
|
|
392
407
|
|
|
393
|
-
const zipRows = this.zipFulltextCompStmt.all(`"${qraw}
|
|
394
|
-
const zipMatches = zipRows.map(
|
|
408
|
+
const zipRows = this.zipFulltextCompStmt.all(`{longname} : "${qraw}" *`);
|
|
409
|
+
const zipMatches = zipRows.map(res => {
|
|
410
|
+
const zipCode = res.ZipCode;
|
|
411
|
+
const loc = this.lookupZip(zipCode);
|
|
412
|
+
const obj = {
|
|
413
|
+
id: zipCode,
|
|
414
|
+
value: loc.getName(),
|
|
415
|
+
admin1: loc.admin1,
|
|
416
|
+
asciiname: loc.getShortName(),
|
|
417
|
+
country: 'United States',
|
|
418
|
+
latitude: loc.latitude,
|
|
419
|
+
longitude: loc.longitude,
|
|
420
|
+
timezone: loc.getTzid(),
|
|
421
|
+
population: loc.population,
|
|
422
|
+
geo: 'zip'
|
|
423
|
+
};
|
|
424
|
+
return obj;
|
|
425
|
+
});
|
|
395
426
|
const map = new Map();
|
|
396
427
|
|
|
397
428
|
for (const obj of zipMatches) {
|
|
@@ -410,7 +441,7 @@ class GeoDb {
|
|
|
410
441
|
|
|
411
442
|
const values = Array.from(map.values());
|
|
412
443
|
values.sort((a, b) => b.population - a.population);
|
|
413
|
-
const topN = values.slice(0,
|
|
444
|
+
const topN = values.slice(0, 15);
|
|
414
445
|
|
|
415
446
|
if (!latlong) {
|
|
416
447
|
for (const val of topN) {
|
|
@@ -601,17 +632,13 @@ async function buildGeonamesSqlite(opts) {
|
|
|
601
632
|
`);
|
|
602
633
|
doSql(logger, db, `update admin1 set name='',asciiname='' where key like 'PS.%';`, `update country set country = '' where iso = 'PS';`, `delete from geoname where geonameid = 7303419;`);
|
|
603
634
|
doSql(logger, db, `DROP TABLE IF EXISTS geoname_fulltext`, `CREATE VIRTUAL TABLE geoname_fulltext
|
|
604
|
-
USING fts5(geonameid,
|
|
605
|
-
longname,
|
|
606
|
-
asciiname, admin1, country,
|
|
607
|
-
population, latitude, longitude, timezone
|
|
608
|
-
);
|
|
635
|
+
USING fts5(geonameid UNINDEXED, longname, population, city, admin1, country);
|
|
609
636
|
`, `DROP TABLE IF EXISTS geoname_non_ascii`, `CREATE TABLE geoname_non_ascii AS
|
|
610
637
|
SELECT geonameid FROM geoname WHERE asciiname <> name`, `INSERT INTO geoname_fulltext
|
|
611
638
|
SELECT g.geonameid,
|
|
612
639
|
g.asciiname||', '||a.asciiname||', '||c.Country,
|
|
613
|
-
g.
|
|
614
|
-
g.
|
|
640
|
+
g.population,
|
|
641
|
+
g.asciiname,a.asciiname,c.Country
|
|
615
642
|
FROM geoname g, admin1 a, country c
|
|
616
643
|
WHERE g.country = c.ISO
|
|
617
644
|
AND g.country <> 'US'
|
|
@@ -619,24 +646,24 @@ async function buildGeonamesSqlite(opts) {
|
|
|
619
646
|
`, `INSERT INTO geoname_fulltext
|
|
620
647
|
SELECT g.geonameid,
|
|
621
648
|
g.asciiname||', '||a.asciiname||', USA',
|
|
622
|
-
g.
|
|
623
|
-
g.
|
|
649
|
+
g.population,
|
|
650
|
+
g.asciiname,a.asciiname,'USA'
|
|
624
651
|
FROM geoname g, admin1 a
|
|
625
652
|
WHERE g.country = 'US'
|
|
626
653
|
AND g.country||'.'||g.admin1 = a.key
|
|
627
654
|
`, `INSERT INTO geoname_fulltext
|
|
628
655
|
SELECT g.geonameid,
|
|
629
656
|
g.asciiname||', '||c.Country,
|
|
630
|
-
g.
|
|
631
|
-
g.
|
|
657
|
+
g.population,
|
|
658
|
+
g.asciiname,NULL,c.Country
|
|
632
659
|
FROM geoname g, country c
|
|
633
660
|
WHERE g.country = c.ISO
|
|
634
661
|
AND (g.admin1 = '' OR g.admin1 = '00')
|
|
635
662
|
`, `INSERT INTO geoname_fulltext
|
|
636
663
|
SELECT g.geonameid,
|
|
637
664
|
g.name||', '||a.name||', '||c.Country,
|
|
638
|
-
g.
|
|
639
|
-
g.
|
|
665
|
+
g.population,
|
|
666
|
+
g.name,a.name,c.Country
|
|
640
667
|
FROM geoname_non_ascii gna, geoname g, admin1 a, country c
|
|
641
668
|
WHERE gna.geonameid = g.geonameid
|
|
642
669
|
AND g.country = c.ISO
|
|
@@ -644,8 +671,8 @@ async function buildGeonamesSqlite(opts) {
|
|
|
644
671
|
`, `INSERT INTO geoname_fulltext
|
|
645
672
|
SELECT g.geonameid,
|
|
646
673
|
alt.name||', ישראל',
|
|
647
|
-
|
|
648
|
-
|
|
674
|
+
g.population,
|
|
675
|
+
alt.name,NULL,'ישראל'
|
|
649
676
|
FROM geoname g, altnames alt
|
|
650
677
|
WHERE g.country = 'IL'
|
|
651
678
|
AND alt.isolanguage = 'he'
|
|
@@ -653,8 +680,8 @@ async function buildGeonamesSqlite(opts) {
|
|
|
653
680
|
`, `INSERT INTO geoname_fulltext
|
|
654
681
|
SELECT g.geonameid,
|
|
655
682
|
alt.name||', '||a1.asciiname||', Israel',
|
|
656
|
-
|
|
657
|
-
|
|
683
|
+
g.population,
|
|
684
|
+
alt.name,a1.asciiname,'Israel'
|
|
658
685
|
FROM geoname g, admin1 a1, altnames alt
|
|
659
686
|
WHERE g.country = 'IL'
|
|
660
687
|
AND alt.isolanguage = 'en'
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! @hebcal/geo-sqlite v4.
|
|
1
|
+
/*! @hebcal/geo-sqlite v4.5.0 */
|
|
2
2
|
import Database from 'better-sqlite3';
|
|
3
3
|
import { Location, Locale } from '@hebcal/core';
|
|
4
4
|
import '@hebcal/cities';
|
|
@@ -17,6 +17,7 @@ const GEONAME_SQL = `SELECT
|
|
|
17
17
|
a.asciiname as admin1,
|
|
18
18
|
g.latitude as latitude,
|
|
19
19
|
g.longitude as longitude,
|
|
20
|
+
g.population as population,
|
|
20
21
|
g.timezone as timezone
|
|
21
22
|
FROM geoname g
|
|
22
23
|
LEFT JOIN country c on g.country = c.iso
|
|
@@ -32,33 +33,29 @@ const GEONAME_ALL_SQL = `SELECT
|
|
|
32
33
|
a.asciiname as admin1,
|
|
33
34
|
g.latitude as latitude,
|
|
34
35
|
g.longitude as longitude,
|
|
36
|
+
g.population as population,
|
|
35
37
|
g.timezone as timezone
|
|
36
38
|
FROM geoname g
|
|
37
39
|
LEFT JOIN country c on g.country = c.iso
|
|
38
40
|
LEFT JOIN admin1 a on g.country||'.'||g.admin1 = a.key
|
|
39
41
|
`;
|
|
40
|
-
const ZIPCODE_SQL = `SELECT CityMixedCase,State,Latitude,Longitude,TimeZone,DayLightSaving
|
|
42
|
+
const ZIPCODE_SQL = `SELECT ZipCode,CityMixedCase,State,Latitude,Longitude,TimeZone,DayLightSaving,Population
|
|
41
43
|
FROM ZIPCodes_Primary WHERE ZipCode = ?`;
|
|
42
|
-
const ZIPCODE_ALL_SQL = `SELECT ZipCode,CityMixedCase,State,Latitude,Longitude,TimeZone,DayLightSaving
|
|
44
|
+
const ZIPCODE_ALL_SQL = `SELECT ZipCode,CityMixedCase,State,Latitude,Longitude,TimeZone,DayLightSaving,Population
|
|
43
45
|
FROM ZIPCodes_Primary`;
|
|
44
46
|
const ZIP_COMPLETE_SQL = `SELECT ZipCode,CityMixedCase,State,Latitude,Longitude,TimeZone,DayLightSaving,Population
|
|
45
47
|
FROM ZIPCodes_Primary
|
|
46
48
|
WHERE ZipCode LIKE ?
|
|
47
49
|
ORDER BY Population DESC
|
|
48
50
|
LIMIT 10`;
|
|
49
|
-
const ZIP_FULLTEXT_COMPLETE_SQL = `SELECT ZipCode
|
|
50
|
-
FROM
|
|
51
|
-
WHERE
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
const GEONAME_COMPLETE_SQL = `SELECT geonameid, asciiname, admin1, country,
|
|
55
|
-
population, latitude, longitude, timezone,
|
|
56
|
-
((sqrt(population)/40) + (-30 * rank)) as myrank
|
|
51
|
+
const ZIP_FULLTEXT_COMPLETE_SQL = `SELECT ZipCode
|
|
52
|
+
FROM ZIPCodes_CityFullText5
|
|
53
|
+
WHERE ZIPCodes_CityFullText5 MATCH ?
|
|
54
|
+
LIMIT 20`;
|
|
55
|
+
const GEONAME_COMPLETE_SQL = `SELECT geonameid
|
|
57
56
|
FROM geoname_fulltext
|
|
58
57
|
WHERE geoname_fulltext MATCH ?
|
|
59
|
-
|
|
60
|
-
ORDER BY myrank DESC
|
|
61
|
-
LIMIT 15`;
|
|
58
|
+
LIMIT 20`;
|
|
62
59
|
const stateNames = {
|
|
63
60
|
'AK': 'Alaska',
|
|
64
61
|
'AL': 'Alabama',
|
|
@@ -214,6 +211,7 @@ class GeoDb {
|
|
|
214
211
|
location.stateName = stateNames[location.state];
|
|
215
212
|
location.geo = 'zip';
|
|
216
213
|
location.zip = zip;
|
|
214
|
+
location.population = result.Population;
|
|
217
215
|
return location;
|
|
218
216
|
}
|
|
219
217
|
/**
|
|
@@ -251,13 +249,9 @@ class GeoDb {
|
|
|
251
249
|
const admin1 = result.admin1 || '';
|
|
252
250
|
const cityDescr = Location.geonameCityDescr(result.name, admin1, country);
|
|
253
251
|
const location = new Location(result.latitude, result.longitude, result.cc == 'IL', result.timezone, cityDescr, result.cc, geonameid);
|
|
254
|
-
|
|
255
|
-
if (result.asciiname !== result.name) {
|
|
256
|
-
location.asciiname = result.asciiname;
|
|
257
|
-
}
|
|
258
|
-
|
|
259
252
|
location.geo = 'geoname';
|
|
260
253
|
location.geonameid = geonameid;
|
|
254
|
+
location.asciiname = result.asciiname;
|
|
261
255
|
|
|
262
256
|
if (admin1) {
|
|
263
257
|
location.admin1 = admin1;
|
|
@@ -267,6 +261,10 @@ class GeoDb {
|
|
|
267
261
|
location.jersualem = true;
|
|
268
262
|
}
|
|
269
263
|
|
|
264
|
+
if (result.population) {
|
|
265
|
+
location.population = result.population;
|
|
266
|
+
}
|
|
267
|
+
|
|
270
268
|
return location;
|
|
271
269
|
}
|
|
272
270
|
/**
|
|
@@ -344,25 +342,42 @@ class GeoDb {
|
|
|
344
342
|
}
|
|
345
343
|
|
|
346
344
|
qraw = qraw.replace(/\"/g, '""');
|
|
347
|
-
const
|
|
345
|
+
const geoRows0 = this.geonamesCompStmt.all(`{longname} : "${qraw}" *`);
|
|
346
|
+
const ids = new Set();
|
|
347
|
+
const geoRows = [];
|
|
348
|
+
|
|
349
|
+
for (const row of geoRows0) {
|
|
350
|
+
const id = row.geonameid;
|
|
351
|
+
|
|
352
|
+
if (!ids.has(id)) {
|
|
353
|
+
ids.add(id);
|
|
354
|
+
geoRows.push(row);
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
|
|
348
358
|
const geoMatches = geoRows.map(res => {
|
|
349
|
-
const
|
|
350
|
-
const
|
|
351
|
-
const
|
|
359
|
+
const loc = this.lookupGeoname(res.geonameid);
|
|
360
|
+
const country = this.countryNames.get(loc.getCountryCode()) || '';
|
|
361
|
+
const admin1 = loc.admin1 || '';
|
|
352
362
|
const obj = {
|
|
353
363
|
id: res.geonameid,
|
|
354
|
-
value:
|
|
355
|
-
asciiname: res.asciiname,
|
|
364
|
+
value: loc.name,
|
|
356
365
|
admin1,
|
|
357
366
|
country,
|
|
358
|
-
latitude:
|
|
359
|
-
longitude:
|
|
360
|
-
timezone:
|
|
361
|
-
|
|
362
|
-
geo: 'geoname',
|
|
363
|
-
rank: rank
|
|
367
|
+
latitude: loc.latitude,
|
|
368
|
+
longitude: loc.longitude,
|
|
369
|
+
timezone: loc.getTzid(),
|
|
370
|
+
geo: 'geoname'
|
|
364
371
|
};
|
|
365
372
|
|
|
373
|
+
if (loc.population) {
|
|
374
|
+
obj.population = loc.population;
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
if (loc.asciiname) {
|
|
378
|
+
obj.asciiname = loc.asciiname;
|
|
379
|
+
}
|
|
380
|
+
|
|
366
381
|
if (country) {
|
|
367
382
|
obj.country = country;
|
|
368
383
|
}
|
|
@@ -378,8 +393,24 @@ class GeoDb {
|
|
|
378
393
|
this.zipFulltextCompStmt = this.zipsDb.prepare(ZIP_FULLTEXT_COMPLETE_SQL);
|
|
379
394
|
}
|
|
380
395
|
|
|
381
|
-
const zipRows = this.zipFulltextCompStmt.all(`"${qraw}
|
|
382
|
-
const zipMatches = zipRows.map(
|
|
396
|
+
const zipRows = this.zipFulltextCompStmt.all(`{longname} : "${qraw}" *`);
|
|
397
|
+
const zipMatches = zipRows.map(res => {
|
|
398
|
+
const zipCode = res.ZipCode;
|
|
399
|
+
const loc = this.lookupZip(zipCode);
|
|
400
|
+
const obj = {
|
|
401
|
+
id: zipCode,
|
|
402
|
+
value: loc.getName(),
|
|
403
|
+
admin1: loc.admin1,
|
|
404
|
+
asciiname: loc.getShortName(),
|
|
405
|
+
country: 'United States',
|
|
406
|
+
latitude: loc.latitude,
|
|
407
|
+
longitude: loc.longitude,
|
|
408
|
+
timezone: loc.getTzid(),
|
|
409
|
+
population: loc.population,
|
|
410
|
+
geo: 'zip'
|
|
411
|
+
};
|
|
412
|
+
return obj;
|
|
413
|
+
});
|
|
383
414
|
const map = new Map();
|
|
384
415
|
|
|
385
416
|
for (const obj of zipMatches) {
|
|
@@ -398,7 +429,7 @@ class GeoDb {
|
|
|
398
429
|
|
|
399
430
|
const values = Array.from(map.values());
|
|
400
431
|
values.sort((a, b) => b.population - a.population);
|
|
401
|
-
const topN = values.slice(0,
|
|
432
|
+
const topN = values.slice(0, 15);
|
|
402
433
|
|
|
403
434
|
if (!latlong) {
|
|
404
435
|
for (const val of topN) {
|
|
@@ -589,17 +620,13 @@ async function buildGeonamesSqlite(opts) {
|
|
|
589
620
|
`);
|
|
590
621
|
doSql(logger, db, `update admin1 set name='',asciiname='' where key like 'PS.%';`, `update country set country = '' where iso = 'PS';`, `delete from geoname where geonameid = 7303419;`);
|
|
591
622
|
doSql(logger, db, `DROP TABLE IF EXISTS geoname_fulltext`, `CREATE VIRTUAL TABLE geoname_fulltext
|
|
592
|
-
USING fts5(geonameid,
|
|
593
|
-
longname,
|
|
594
|
-
asciiname, admin1, country,
|
|
595
|
-
population, latitude, longitude, timezone
|
|
596
|
-
);
|
|
623
|
+
USING fts5(geonameid UNINDEXED, longname, population, city, admin1, country);
|
|
597
624
|
`, `DROP TABLE IF EXISTS geoname_non_ascii`, `CREATE TABLE geoname_non_ascii AS
|
|
598
625
|
SELECT geonameid FROM geoname WHERE asciiname <> name`, `INSERT INTO geoname_fulltext
|
|
599
626
|
SELECT g.geonameid,
|
|
600
627
|
g.asciiname||', '||a.asciiname||', '||c.Country,
|
|
601
|
-
g.
|
|
602
|
-
g.
|
|
628
|
+
g.population,
|
|
629
|
+
g.asciiname,a.asciiname,c.Country
|
|
603
630
|
FROM geoname g, admin1 a, country c
|
|
604
631
|
WHERE g.country = c.ISO
|
|
605
632
|
AND g.country <> 'US'
|
|
@@ -607,24 +634,24 @@ async function buildGeonamesSqlite(opts) {
|
|
|
607
634
|
`, `INSERT INTO geoname_fulltext
|
|
608
635
|
SELECT g.geonameid,
|
|
609
636
|
g.asciiname||', '||a.asciiname||', USA',
|
|
610
|
-
g.
|
|
611
|
-
g.
|
|
637
|
+
g.population,
|
|
638
|
+
g.asciiname,a.asciiname,'USA'
|
|
612
639
|
FROM geoname g, admin1 a
|
|
613
640
|
WHERE g.country = 'US'
|
|
614
641
|
AND g.country||'.'||g.admin1 = a.key
|
|
615
642
|
`, `INSERT INTO geoname_fulltext
|
|
616
643
|
SELECT g.geonameid,
|
|
617
644
|
g.asciiname||', '||c.Country,
|
|
618
|
-
g.
|
|
619
|
-
g.
|
|
645
|
+
g.population,
|
|
646
|
+
g.asciiname,NULL,c.Country
|
|
620
647
|
FROM geoname g, country c
|
|
621
648
|
WHERE g.country = c.ISO
|
|
622
649
|
AND (g.admin1 = '' OR g.admin1 = '00')
|
|
623
650
|
`, `INSERT INTO geoname_fulltext
|
|
624
651
|
SELECT g.geonameid,
|
|
625
652
|
g.name||', '||a.name||', '||c.Country,
|
|
626
|
-
g.
|
|
627
|
-
g.
|
|
653
|
+
g.population,
|
|
654
|
+
g.name,a.name,c.Country
|
|
628
655
|
FROM geoname_non_ascii gna, geoname g, admin1 a, country c
|
|
629
656
|
WHERE gna.geonameid = g.geonameid
|
|
630
657
|
AND g.country = c.ISO
|
|
@@ -632,8 +659,8 @@ async function buildGeonamesSqlite(opts) {
|
|
|
632
659
|
`, `INSERT INTO geoname_fulltext
|
|
633
660
|
SELECT g.geonameid,
|
|
634
661
|
alt.name||', ישראל',
|
|
635
|
-
|
|
636
|
-
|
|
662
|
+
g.population,
|
|
663
|
+
alt.name,NULL,'ישראל'
|
|
637
664
|
FROM geoname g, altnames alt
|
|
638
665
|
WHERE g.country = 'IL'
|
|
639
666
|
AND alt.isolanguage = 'he'
|
|
@@ -641,8 +668,8 @@ async function buildGeonamesSqlite(opts) {
|
|
|
641
668
|
`, `INSERT INTO geoname_fulltext
|
|
642
669
|
SELECT g.geonameid,
|
|
643
670
|
alt.name||', '||a1.asciiname||', Israel',
|
|
644
|
-
|
|
645
|
-
|
|
671
|
+
g.population,
|
|
672
|
+
alt.name,a1.asciiname,'Israel'
|
|
646
673
|
FROM geoname g, admin1 a1, altnames alt
|
|
647
674
|
WHERE g.country = 'IL'
|
|
648
675
|
AND alt.isolanguage = 'en'
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hebcal/geo-sqlite",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.5.0",
|
|
4
4
|
"author": "Michael J. Radwin (https://github.com/mjradwin)",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"hebcal"
|
|
@@ -29,8 +29,8 @@
|
|
|
29
29
|
],
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"@hebcal/cities": "^3.1.2",
|
|
32
|
-
"@hebcal/core": "^3.
|
|
33
|
-
"better-sqlite3": "^7.5.
|
|
32
|
+
"@hebcal/core": "^3.38.0",
|
|
33
|
+
"better-sqlite3": "^7.5.3",
|
|
34
34
|
"pino": "^7.11.0",
|
|
35
35
|
"pino-pretty": "^7.6.1"
|
|
36
36
|
},
|
|
@@ -53,18 +53,18 @@
|
|
|
53
53
|
},
|
|
54
54
|
"license": "BSD-2-Clause",
|
|
55
55
|
"devDependencies": {
|
|
56
|
-
"@babel/core": "^7.
|
|
57
|
-
"@babel/preset-env": "^7.
|
|
56
|
+
"@babel/core": "^7.18.2",
|
|
57
|
+
"@babel/preset-env": "^7.18.2",
|
|
58
58
|
"@babel/register": "^7.17.7",
|
|
59
59
|
"@rollup/plugin-babel": "^5.3.1",
|
|
60
60
|
"@rollup/plugin-commonjs": "^22.0.0",
|
|
61
61
|
"@rollup/plugin-json": "^4.1.0",
|
|
62
|
-
"@rollup/plugin-node-resolve": "^13.
|
|
62
|
+
"@rollup/plugin-node-resolve": "^13.3.0",
|
|
63
63
|
"ava": "^4.2.0",
|
|
64
|
-
"eslint": "^8.
|
|
64
|
+
"eslint": "^8.16.0",
|
|
65
65
|
"eslint-config-google": "^0.14.0",
|
|
66
66
|
"jsdoc": "^3.6.10",
|
|
67
67
|
"jsdoc-to-markdown": "^7.1.1",
|
|
68
|
-
"rollup": "^2.
|
|
68
|
+
"rollup": "^2.75.4"
|
|
69
69
|
}
|
|
70
70
|
}
|
package/zips-dummy.sql
CHANGED
|
@@ -10,4 +10,7 @@ CREATE TABLE ZIPCodes_Primary (
|
|
|
10
10
|
);
|
|
11
11
|
|
|
12
12
|
CREATE VIRTUAL TABLE ZIPCodes_CityFullText
|
|
13
|
-
USING
|
|
13
|
+
USING fts4(ZipCode,CityMixedCase,State,Latitude,Longitude,TimeZone,DayLightSaving,Population);
|
|
14
|
+
|
|
15
|
+
CREATE VIRTUAL TABLE ZIPCodes_CityFullText5
|
|
16
|
+
USING fts5(ZipCode UNINDEXED,CityMixedCase,Population UNINDEXED,longname);
|