@hebcal/geo-sqlite 4.4.0 → 4.4.3
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 +93 -47
- package/dist/index.mjs +93 -47
- 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.4.
|
|
1
|
+
/*! @hebcal/geo-sqlite v4.4.3 */
|
|
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, rank
|
|
64
|
+
FROM ZIPCodes_CityFullText5
|
|
65
|
+
WHERE ZIPCodes_CityFullText5 MATCH ?
|
|
66
|
+
LIMIT 20`;
|
|
67
|
+
const GEONAME_COMPLETE_SQL = `SELECT geonameid, rank
|
|
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,44 @@ 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 || '';
|
|
374
|
+
const rankPop = Math.sqrt(loc.population) / 40;
|
|
364
375
|
const obj = {
|
|
365
376
|
id: res.geonameid,
|
|
366
|
-
value:
|
|
367
|
-
asciiname: res.asciiname,
|
|
377
|
+
value: loc.name,
|
|
368
378
|
admin1,
|
|
369
379
|
country,
|
|
370
|
-
latitude:
|
|
371
|
-
longitude:
|
|
372
|
-
timezone:
|
|
373
|
-
population: res.population,
|
|
380
|
+
latitude: loc.latitude,
|
|
381
|
+
longitude: loc.longitude,
|
|
382
|
+
timezone: loc.getTzid(),
|
|
374
383
|
geo: 'geoname',
|
|
375
|
-
rank: rank
|
|
384
|
+
rank: rankPop + -30 * res.rank
|
|
376
385
|
};
|
|
377
386
|
|
|
387
|
+
if (loc.population) {
|
|
388
|
+
obj.population = loc.population;
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
if (loc.asciiname) {
|
|
392
|
+
obj.asciiname = loc.asciiname;
|
|
393
|
+
}
|
|
394
|
+
|
|
378
395
|
if (country) {
|
|
379
396
|
obj.country = country;
|
|
380
397
|
}
|
|
@@ -390,8 +407,26 @@ class GeoDb {
|
|
|
390
407
|
this.zipFulltextCompStmt = this.zipsDb.prepare(ZIP_FULLTEXT_COMPLETE_SQL);
|
|
391
408
|
}
|
|
392
409
|
|
|
393
|
-
const zipRows = this.zipFulltextCompStmt.all(`"${qraw}
|
|
394
|
-
const zipMatches = zipRows.map(
|
|
410
|
+
const zipRows = this.zipFulltextCompStmt.all(`{longname} : "${qraw}" *`);
|
|
411
|
+
const zipMatches = zipRows.map(res => {
|
|
412
|
+
const zipCode = res.ZipCode;
|
|
413
|
+
const loc = this.lookupZip(zipCode);
|
|
414
|
+
const rankPop = Math.sqrt(loc.population) / 40;
|
|
415
|
+
const obj = {
|
|
416
|
+
id: zipCode,
|
|
417
|
+
value: loc.getName(),
|
|
418
|
+
admin1: loc.admin1,
|
|
419
|
+
asciiname: loc.getShortName(),
|
|
420
|
+
country: 'United States',
|
|
421
|
+
latitude: loc.latitude,
|
|
422
|
+
longitude: loc.longitude,
|
|
423
|
+
timezone: loc.getTzid(),
|
|
424
|
+
population: loc.population,
|
|
425
|
+
geo: 'zip',
|
|
426
|
+
rank: rankPop + -30 * res.rank
|
|
427
|
+
};
|
|
428
|
+
return obj;
|
|
429
|
+
});
|
|
395
430
|
const map = new Map();
|
|
396
431
|
|
|
397
432
|
for (const obj of zipMatches) {
|
|
@@ -409,7 +444,7 @@ class GeoDb {
|
|
|
409
444
|
}
|
|
410
445
|
|
|
411
446
|
const values = Array.from(map.values());
|
|
412
|
-
values.sort((a, b) => b.
|
|
447
|
+
values.sort((a, b) => b.rank - a.rank);
|
|
413
448
|
const topN = values.slice(0, 10);
|
|
414
449
|
|
|
415
450
|
if (!latlong) {
|
|
@@ -601,45 +636,56 @@ async function buildGeonamesSqlite(opts) {
|
|
|
601
636
|
`);
|
|
602
637
|
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
638
|
doSql(logger, db, `DROP TABLE IF EXISTS geoname_fulltext`, `CREATE VIRTUAL TABLE geoname_fulltext
|
|
604
|
-
USING fts5(geonameid,
|
|
605
|
-
asciiname, admin1, country,
|
|
606
|
-
population, latitude, longitude, timezone
|
|
607
|
-
);
|
|
639
|
+
USING fts5(geonameid UNINDEXED, longname, population, city, admin1, country);
|
|
608
640
|
`, `DROP TABLE IF EXISTS geoname_non_ascii`, `CREATE TABLE geoname_non_ascii AS
|
|
609
641
|
SELECT geonameid FROM geoname WHERE asciiname <> name`, `INSERT INTO geoname_fulltext
|
|
610
642
|
SELECT g.geonameid,
|
|
611
|
-
g.asciiname, a.asciiname, c.Country,
|
|
612
|
-
g.population,
|
|
643
|
+
g.asciiname||', '||a.asciiname||', '||c.Country,
|
|
644
|
+
g.population,
|
|
645
|
+
g.asciiname,a.asciiname,c.Country
|
|
613
646
|
FROM geoname g, admin1 a, country c
|
|
614
647
|
WHERE g.country = c.ISO
|
|
648
|
+
AND g.country <> 'US'
|
|
649
|
+
AND g.country||'.'||g.admin1 = a.key
|
|
650
|
+
`, `INSERT INTO geoname_fulltext
|
|
651
|
+
SELECT g.geonameid,
|
|
652
|
+
g.asciiname||', '||a.asciiname||', USA',
|
|
653
|
+
g.population,
|
|
654
|
+
g.asciiname,a.asciiname,'USA'
|
|
655
|
+
FROM geoname g, admin1 a
|
|
656
|
+
WHERE g.country = 'US'
|
|
615
657
|
AND g.country||'.'||g.admin1 = a.key
|
|
616
658
|
`, `INSERT INTO geoname_fulltext
|
|
617
659
|
SELECT g.geonameid,
|
|
618
|
-
g.asciiname, '
|
|
619
|
-
g.population,
|
|
660
|
+
g.asciiname||', '||c.Country,
|
|
661
|
+
g.population,
|
|
662
|
+
g.asciiname,NULL,c.Country
|
|
620
663
|
FROM geoname g, country c
|
|
621
664
|
WHERE g.country = c.ISO
|
|
622
665
|
AND (g.admin1 = '' OR g.admin1 = '00')
|
|
623
666
|
`, `INSERT INTO geoname_fulltext
|
|
624
667
|
SELECT g.geonameid,
|
|
625
|
-
g.name, a.name, c.Country,
|
|
626
|
-
g.population,
|
|
668
|
+
g.name||', '||a.name||', '||c.Country,
|
|
669
|
+
g.population,
|
|
670
|
+
g.name,a.name,c.Country
|
|
627
671
|
FROM geoname_non_ascii gna, geoname g, admin1 a, country c
|
|
628
672
|
WHERE gna.geonameid = g.geonameid
|
|
629
673
|
AND g.country = c.ISO
|
|
630
674
|
AND g.country||'.'||g.admin1 = a.key
|
|
631
675
|
`, `INSERT INTO geoname_fulltext
|
|
632
676
|
SELECT g.geonameid,
|
|
633
|
-
alt.name
|
|
634
|
-
g.population,
|
|
677
|
+
alt.name||', ישראל',
|
|
678
|
+
g.population,
|
|
679
|
+
alt.name,NULL,'ישראל'
|
|
635
680
|
FROM geoname g, altnames alt
|
|
636
681
|
WHERE g.country = 'IL'
|
|
637
682
|
AND alt.isolanguage = 'he'
|
|
638
683
|
AND g.geonameid = alt.geonameid
|
|
639
684
|
`, `INSERT INTO geoname_fulltext
|
|
640
685
|
SELECT g.geonameid,
|
|
641
|
-
alt.name, a1.asciiname,
|
|
642
|
-
g.population,
|
|
686
|
+
alt.name||', '||a1.asciiname||', Israel',
|
|
687
|
+
g.population,
|
|
688
|
+
alt.name,a1.asciiname,'Israel'
|
|
643
689
|
FROM geoname g, admin1 a1, altnames alt
|
|
644
690
|
WHERE g.country = 'IL'
|
|
645
691
|
AND alt.isolanguage = 'en'
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! @hebcal/geo-sqlite v4.4.
|
|
1
|
+
/*! @hebcal/geo-sqlite v4.4.3 */
|
|
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, rank
|
|
52
|
+
FROM ZIPCodes_CityFullText5
|
|
53
|
+
WHERE ZIPCodes_CityFullText5 MATCH ?
|
|
54
|
+
LIMIT 20`;
|
|
55
|
+
const GEONAME_COMPLETE_SQL = `SELECT geonameid, rank
|
|
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,44 @@ 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 || '';
|
|
362
|
+
const rankPop = Math.sqrt(loc.population) / 40;
|
|
352
363
|
const obj = {
|
|
353
364
|
id: res.geonameid,
|
|
354
|
-
value:
|
|
355
|
-
asciiname: res.asciiname,
|
|
365
|
+
value: loc.name,
|
|
356
366
|
admin1,
|
|
357
367
|
country,
|
|
358
|
-
latitude:
|
|
359
|
-
longitude:
|
|
360
|
-
timezone:
|
|
361
|
-
population: res.population,
|
|
368
|
+
latitude: loc.latitude,
|
|
369
|
+
longitude: loc.longitude,
|
|
370
|
+
timezone: loc.getTzid(),
|
|
362
371
|
geo: 'geoname',
|
|
363
|
-
rank: rank
|
|
372
|
+
rank: rankPop + -30 * res.rank
|
|
364
373
|
};
|
|
365
374
|
|
|
375
|
+
if (loc.population) {
|
|
376
|
+
obj.population = loc.population;
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
if (loc.asciiname) {
|
|
380
|
+
obj.asciiname = loc.asciiname;
|
|
381
|
+
}
|
|
382
|
+
|
|
366
383
|
if (country) {
|
|
367
384
|
obj.country = country;
|
|
368
385
|
}
|
|
@@ -378,8 +395,26 @@ class GeoDb {
|
|
|
378
395
|
this.zipFulltextCompStmt = this.zipsDb.prepare(ZIP_FULLTEXT_COMPLETE_SQL);
|
|
379
396
|
}
|
|
380
397
|
|
|
381
|
-
const zipRows = this.zipFulltextCompStmt.all(`"${qraw}
|
|
382
|
-
const zipMatches = zipRows.map(
|
|
398
|
+
const zipRows = this.zipFulltextCompStmt.all(`{longname} : "${qraw}" *`);
|
|
399
|
+
const zipMatches = zipRows.map(res => {
|
|
400
|
+
const zipCode = res.ZipCode;
|
|
401
|
+
const loc = this.lookupZip(zipCode);
|
|
402
|
+
const rankPop = Math.sqrt(loc.population) / 40;
|
|
403
|
+
const obj = {
|
|
404
|
+
id: zipCode,
|
|
405
|
+
value: loc.getName(),
|
|
406
|
+
admin1: loc.admin1,
|
|
407
|
+
asciiname: loc.getShortName(),
|
|
408
|
+
country: 'United States',
|
|
409
|
+
latitude: loc.latitude,
|
|
410
|
+
longitude: loc.longitude,
|
|
411
|
+
timezone: loc.getTzid(),
|
|
412
|
+
population: loc.population,
|
|
413
|
+
geo: 'zip',
|
|
414
|
+
rank: rankPop + -30 * res.rank
|
|
415
|
+
};
|
|
416
|
+
return obj;
|
|
417
|
+
});
|
|
383
418
|
const map = new Map();
|
|
384
419
|
|
|
385
420
|
for (const obj of zipMatches) {
|
|
@@ -397,7 +432,7 @@ class GeoDb {
|
|
|
397
432
|
}
|
|
398
433
|
|
|
399
434
|
const values = Array.from(map.values());
|
|
400
|
-
values.sort((a, b) => b.
|
|
435
|
+
values.sort((a, b) => b.rank - a.rank);
|
|
401
436
|
const topN = values.slice(0, 10);
|
|
402
437
|
|
|
403
438
|
if (!latlong) {
|
|
@@ -589,45 +624,56 @@ async function buildGeonamesSqlite(opts) {
|
|
|
589
624
|
`);
|
|
590
625
|
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
626
|
doSql(logger, db, `DROP TABLE IF EXISTS geoname_fulltext`, `CREATE VIRTUAL TABLE geoname_fulltext
|
|
592
|
-
USING fts5(geonameid,
|
|
593
|
-
asciiname, admin1, country,
|
|
594
|
-
population, latitude, longitude, timezone
|
|
595
|
-
);
|
|
627
|
+
USING fts5(geonameid UNINDEXED, longname, population, city, admin1, country);
|
|
596
628
|
`, `DROP TABLE IF EXISTS geoname_non_ascii`, `CREATE TABLE geoname_non_ascii AS
|
|
597
629
|
SELECT geonameid FROM geoname WHERE asciiname <> name`, `INSERT INTO geoname_fulltext
|
|
598
630
|
SELECT g.geonameid,
|
|
599
|
-
g.asciiname, a.asciiname, c.Country,
|
|
600
|
-
g.population,
|
|
631
|
+
g.asciiname||', '||a.asciiname||', '||c.Country,
|
|
632
|
+
g.population,
|
|
633
|
+
g.asciiname,a.asciiname,c.Country
|
|
601
634
|
FROM geoname g, admin1 a, country c
|
|
602
635
|
WHERE g.country = c.ISO
|
|
636
|
+
AND g.country <> 'US'
|
|
637
|
+
AND g.country||'.'||g.admin1 = a.key
|
|
638
|
+
`, `INSERT INTO geoname_fulltext
|
|
639
|
+
SELECT g.geonameid,
|
|
640
|
+
g.asciiname||', '||a.asciiname||', USA',
|
|
641
|
+
g.population,
|
|
642
|
+
g.asciiname,a.asciiname,'USA'
|
|
643
|
+
FROM geoname g, admin1 a
|
|
644
|
+
WHERE g.country = 'US'
|
|
603
645
|
AND g.country||'.'||g.admin1 = a.key
|
|
604
646
|
`, `INSERT INTO geoname_fulltext
|
|
605
647
|
SELECT g.geonameid,
|
|
606
|
-
g.asciiname, '
|
|
607
|
-
g.population,
|
|
648
|
+
g.asciiname||', '||c.Country,
|
|
649
|
+
g.population,
|
|
650
|
+
g.asciiname,NULL,c.Country
|
|
608
651
|
FROM geoname g, country c
|
|
609
652
|
WHERE g.country = c.ISO
|
|
610
653
|
AND (g.admin1 = '' OR g.admin1 = '00')
|
|
611
654
|
`, `INSERT INTO geoname_fulltext
|
|
612
655
|
SELECT g.geonameid,
|
|
613
|
-
g.name, a.name, c.Country,
|
|
614
|
-
g.population,
|
|
656
|
+
g.name||', '||a.name||', '||c.Country,
|
|
657
|
+
g.population,
|
|
658
|
+
g.name,a.name,c.Country
|
|
615
659
|
FROM geoname_non_ascii gna, geoname g, admin1 a, country c
|
|
616
660
|
WHERE gna.geonameid = g.geonameid
|
|
617
661
|
AND g.country = c.ISO
|
|
618
662
|
AND g.country||'.'||g.admin1 = a.key
|
|
619
663
|
`, `INSERT INTO geoname_fulltext
|
|
620
664
|
SELECT g.geonameid,
|
|
621
|
-
alt.name
|
|
622
|
-
g.population,
|
|
665
|
+
alt.name||', ישראל',
|
|
666
|
+
g.population,
|
|
667
|
+
alt.name,NULL,'ישראל'
|
|
623
668
|
FROM geoname g, altnames alt
|
|
624
669
|
WHERE g.country = 'IL'
|
|
625
670
|
AND alt.isolanguage = 'he'
|
|
626
671
|
AND g.geonameid = alt.geonameid
|
|
627
672
|
`, `INSERT INTO geoname_fulltext
|
|
628
673
|
SELECT g.geonameid,
|
|
629
|
-
alt.name, a1.asciiname,
|
|
630
|
-
g.population,
|
|
674
|
+
alt.name||', '||a1.asciiname||', Israel',
|
|
675
|
+
g.population,
|
|
676
|
+
alt.name,a1.asciiname,'Israel'
|
|
631
677
|
FROM geoname g, admin1 a1, altnames alt
|
|
632
678
|
WHERE g.country = 'IL'
|
|
633
679
|
AND alt.isolanguage = 'en'
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hebcal/geo-sqlite",
|
|
3
|
-
"version": "4.4.
|
|
3
|
+
"version": "4.4.3",
|
|
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);
|