Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable postalcode lookup #310

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ Who's On First Admin Lookup module recognizes the following top-level properties
{
"imports": {
"adminLookup": {
"enabled": true
"enabled": true,
"lookupPostalCodes": false
},
"whosonfirst": {
"datapath": "/path/to/wof-data"
Expand Down Expand Up @@ -120,6 +121,8 @@ The `weight` field is used to determine which entry is the most important, this

To enable the postal cities functionality, set `imports.adminLookup.usePostalCities` to `true` in your `pelias.json` file.

To enable the lookup of postalcodes, set `imports.adminLookup.lookupPostalCodes` to `true` in your `pelias.json` file. Because postal code data can amount to a significant size, this setting is disabled by default.

#### Advanced Configuration

It's possible to use your own mapping files by setting `imports.adminLookup.postalCitiesDataPath` to point to a directory of your choice, if the corresponding TSV file is found in your path it will be used in place of the bundled data files. [more information](https://github.com/pelias/wof-admin-lookup/pull/296).
1 change: 1 addition & 0 deletions schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ module.exports = Joi.object().keys({
enabled: Joi.boolean().default(true),
missingMetafilesAreFatal: Joi.boolean().default(false),
usePostalCities: Joi.boolean().default(false),
lookupPostalCodes: Joi.boolean().default(false),
postalCitiesDataPath: Joi.string()
}).unknown(true),
whosonfirst: Joi.object().keys({
Expand Down
9 changes: 6 additions & 3 deletions src/pip/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ const logger = require( 'pelias-logger' ).get( 'wof-pip-service:master' );
const async = require('async');
const _ = require('lodash');
const fs = require('fs');
const missingMetafilesAreFatal = require('pelias-config').generate(require('../../schema')).imports.adminLookup.missingMetafilesAreFatal;
const config = require('pelias-config').generate(require('../../schema')).imports.adminLookup;
const missingMetafilesAreFatal = config.missingMetafilesAreFatal;
const lookupPostalCodes = config.lookupPostalCodes;

let requestCount = 0;
// worker processes keyed on layer
Expand All @@ -22,6 +24,7 @@ const wofData = {};

const defaultLayers = [
'neighbourhood',
...(lookupPostalCodes ? ['postalcode'] : []),
'borough',
'locality',
'localadmin',
Expand Down Expand Up @@ -184,8 +187,8 @@ function handleResults(msg) {
}

} else {
// there was a hit, so find the hierachy and assemble all the pieces
const untrustedLayers = ['neighbourhood'];
// there was a hit, so find the hierarchy and assemble all the pieces
const untrustedLayers = ['neighbourhood', 'postalcode'];

if (untrustedLayers.includes(msg.layer)) {
// push _only_ the first layers results onto the hierarchy
Expand Down
2 changes: 1 addition & 1 deletion src/service/PointInPolygon.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const ServiceConfiguration = require('pelias-microservice-wrapper').ServiceConfi

// allow searching only against land layers, or a filtered subset of land layers
function calculateLayers(inputLayers) {
const allowedLayers = [ 'neighbourhood', 'borough', 'locality', 'localadmin', 'county',
const allowedLayers = [ 'neighbourhood', 'postalcode', 'borough', 'locality', 'localadmin', 'county',
'macrocounty', 'region', 'macroregion', 'dependency', 'country' ];

// if no input layers are specified, return all of the allowed layers
Expand Down
2 changes: 1 addition & 1 deletion test/remotePipResolverTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const nock = require('nock');
const remotePipResolver = require('../src/remotePipResolver');

// helper var for enumberating all the layer parameters sent in all queries
const layers = [ 'neighbourhood', 'borough', 'locality', 'localadmin', 'county',
const layers = [ 'neighbourhood', 'postalcode', 'borough', 'locality', 'localadmin', 'county',
'macrocounty', 'region', 'macroregion', 'dependency', 'country' ];

tape('tests', (test) => {
Expand Down
2 changes: 1 addition & 1 deletion test/service/PointInPolygon.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ tape('PointInPolygon service configuration tests', (test) => {
const pointInPolygon = new PointInPolygon(config);

const expectedParams = {
layers: [ 'neighbourhood', 'borough', 'locality', 'localadmin', 'county',
layers: [ 'neighbourhood', 'postalcode', 'borough', 'locality', 'localadmin', 'county',
'macrocounty', 'region', 'macroregion', 'dependency', 'country' ]
};

Expand Down