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

Merge staging into production #895

Merged
merged 28 commits into from
May 30, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
17a28d8
chore(package): update pelias-model to version 4.8.0
greenkeeperio-bot Apr 20, 2017
d4ec375
Merge pull request #861 from pelias/greenkeeper-pelias-model-4.8.0
orangejulius Apr 26, 2017
75f44f9
fix(package): update addressit to version 1.5.0
greenkeeper[bot] Apr 27, 2017
6b0b124
Always query for a minimum of 20 results from Elasticsearch
orangejulius Apr 28, 2017
3427058
fix: Merge pull request #874 from pelias/size-param-improvements
orangejulius Apr 28, 2017
af2a888
fix(package): update pelias-config to version 2.10.0
greenkeeper[bot] May 3, 2017
df71d2c
Merge pull request #870 from pelias/greenkeeper/addressit-1.5.0
May 5, 2017
387ecd6
fix(package): update pelias-text-analyzer to version 1.8.1
greenkeeper[bot] May 5, 2017
3978907
fix(package): update pelias-text-analyzer to version 1.8.2
greenkeeper[bot] May 5, 2017
7534407
Merge pull request #876 from pelias/greenkeeper/pelias-config-2.10.0
May 5, 2017
836c941
Merge pull request #877 from pelias/greenkeeper/pelias-text-analyzer-…
May 5, 2017
826f6b0
Merge branch 'master' into greenkeeper/pelias-text-analyzer-1.8.2
May 5, 2017
c2d2930
fix(package): update pelias-model to version 4.8.1
greenkeeper[bot] May 5, 2017
708e71a
Merge pull request #882 from pelias/master
May 8, 2017
1a8fe30
Add config details
May 9, 2017
a5370e0
add an example
May 9, 2017
a660d7e
textAnalyzer not required
May 9, 2017
16c8db8
Merge pull request #883 from pelias/config-doc
May 9, 2017
eae0a65
chore(package): update uglify-js to version 3.0.4
greenkeeper[bot] May 11, 2017
7d3ae79
fix(package): update extend to version 3.0.1
greenkeeper[bot] Apr 28, 2017
34809ce
Use carat version of extend
orangejulius May 12, 2017
fde904f
Merge pull request #873 from pelias/greenkeeper/extend-3.0.1
orangejulius May 12, 2017
092e1c0
Merge pull request #886 from pelias/greenkeeper/uglify-js-3.0.4
orangejulius May 15, 2017
512cec9
Prefer openaddresses results with zip code
kevincennis May 15, 2017
6309f68
Merge pull request #890 from kevincennis/kce/prefer-oa-results-with-zip
May 17, 2017
fd7a14f
Merge pull request #878 from pelias/greenkeeper/pelias-text-analyzer-…
May 17, 2017
f93aa17
Merge pull request #879 from pelias/greenkeeper/pelias-model-4.8.1
May 17, 2017
7e42fb5
Merge pull request #891 from pelias/master
orangejulius May 19, 2017
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
48 changes: 46 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,53 @@ The API ships with several convenience commands (runnable via `npm`):
## pelias-config
The API recognizes the following properties under the top-level `api` key in your `pelias.json` config file:

* `accessLog`: (*optional*) The name of the format to use for access logs; may be any one of the
|parameter|required|default|description|
|---|---|---|---|
|`host`|*yes*||specifies the url under which the http service is to run|
|`textAnalyzer`|*no*|*addressit*|can be either `libpostal` or `addressit` however will soon be **deprecated** and only `libpostal` will be supported going forward|
|`indexName`|*no*|*pelias*|name of the Elasticsearch index to be used when building queries|
|`legacyUrl`|*no*||the url to redirect to in case the user does not specify a version such as `v1`
|`relativeScores`|*no*|true|if set to true, confidence scores will be normalized, realistically at this point setting this to false is not tested or desirable
|`accessLog`|*no*||name of the format to use for access logs; may be any one of the
[predefined values](https://github.com/expressjs/morgan#predefined-formats) in the `morgan` package. Defaults to
`"common"`; if set to `false`, or an otherwise falsy value, disables access-logging entirely.
`"common"`; if set to `false`, or an otherwise falsy value, disables access-logging entirely.|
|`pipService`|*yes*||full url to the pip service to be used for coarse reverse queries. if missing, which is not recommended, the service will default to using nearby lookups instead of point-in-polygon.|

Example configuration file would look something like this:

```
{
"esclient": {
"keepAlive": true,
"requestTimeout": "1200000",
"hosts": [
{
"protocol": "http",
"host": "somesemachine.elb.amazonaws.com",
"port": 9200
}
]
},
"api": {
"host": "localhost:3100/v1/",
"indexName": "foobar",
"legacyUrl": "pelias.mapzen.com",
"relativeScores": true,
"textAnalyzer": "libpostal",
"pipService": "http://mypipservice.com/3000"
},
"interpolation": {
"client": {
"adapter": "http",
"host": "internal-pelias-interpolation-dev-130430937.us-east-1.elb.amazonaws.com"
}
},
"logger": {
"level": "debug"
}
}
```


## Contributing

Expand Down
8 changes: 8 additions & 0 deletions middleware/dedupe.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@ function dedupeResults(req, res, next) {
function isPreferred(existing, candidateReplacement) {
// NOTE: we are assuming here that the layer for both records is the same

var isOA = _.flow(_.property('source'), _.eq.bind(null, 'openaddresses'));
var hasZip = _.bind(_.has, null, _.bind.placeholder, 'address_parts.zip');

// https://github.com/pelias/api/issues/872
if (isOA(existing) && isOA(candidateReplacement)) {
return hasZip(candidateReplacement) && !hasZip(existing);
}

//bind the trumps function to the data items to keep the rest of the function clean
var trumpsFunc = trumps.bind(null, existing, candidateReplacement);

Expand Down
11 changes: 4 additions & 7 deletions middleware/sizeCalculator.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ var _ = require('lodash');

var SIZE_PADDING = 2;

var MIN_QUERY_SIZE = 20;

/**
* Utility for calculating query result size
* incorporating padding for dedupe process
Expand All @@ -24,12 +26,7 @@ function setup() {
* @returns {number}
*/
function calculateSize(cleanSize) {
switch (cleanSize || 1) {
case 1:
return 1;
default:
return cleanSize * SIZE_PADDING;
}
return Math.max(MIN_QUERY_SIZE, cleanSize * SIZE_PADDING);
}

module.exports = setup;
module.exports = setup;
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@
"node": ">=4.0.0"
},
"dependencies": {
"addressit": "1.4.0",
"addressit": "1.5.0",
"async": "^2.0.0",
"check-types": "^7.0.0",
"elasticsearch": "^12.0.1",
"elasticsearch-exceptions": "0.0.4",
"express": "^4.8.8",
"express-http-proxy": "^0.11.0",
"extend": "3.0.0",
"extend": "^3.0.1",
"geojson": "^0.4.0",
"geojson-extent": "^0.3.1",
"geolib": "^2.0.18",
Expand All @@ -55,14 +55,14 @@
"lodash": "^4.5.0",
"markdown": "0.5.0",
"morgan": "1.8.1",
"pelias-config": "2.9.0",
"pelias-config": "2.10.0",
"pelias-categories": "1.2.0",
"pelias-labels": "1.6.0",
"pelias-logger": "0.2.0",
"pelias-mock-logger": "^1.0.1",
"pelias-model": "4.6.0",
"pelias-model": "4.8.1",
"pelias-query": "8.15.0",
"pelias-text-analyzer": "1.8.0",
"pelias-text-analyzer": "1.8.2",
"predicates": "^1.0.1",
"retry": "^0.10.1",
"request": "^2.79.0",
Expand All @@ -84,7 +84,7 @@
"tap-dot": "1.0.5",
"tape": "^4.5.1",
"tmp": "0.0.31",
"uglify-js": "^2.6.2"
"uglify-js": "^3.0.4"
},
"pre-commit": [
"lint",
Expand Down
12 changes: 10 additions & 2 deletions test/unit/helper/sizeCalculator.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ module.exports.tests.valid = function(test, common) {
test('size=0', function (t) {
setup(0);
calcSize(req, {}, function () {
t.equal(req.clean.querySize, 1);
t.equal(req.clean.querySize, 20);
t.end();
});
});

test('size=1', function (t) {
setup(1);
calcSize(req, {}, function () {
t.equal(req.clean.querySize, 1);
t.equal(req.clean.querySize, 20);
t.end();
});
});
Expand All @@ -46,6 +46,14 @@ module.exports.tests.valid = function(test, common) {
});
});

test('size=20', function (t) {
setup(20);
calcSize(req, {}, function () {
t.equal(req.clean.querySize, 40);
t.end();
});
});

test('no size', function (t) {
setup();
calcSize(req, {}, function () {
Expand Down
36 changes: 36 additions & 0 deletions test/unit/middleware/dedupe.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,42 @@ module.exports.tests.trump = function(test, common) {
t.end();
});
});

test('openaddresses with zip trumps openaddresses without zip', function (t) {
var req = {
clean: {
text: '100 Main St',
size: 100
}
};
var res = {
data: [
{
'name': { 'default': '100 Main St' },
'source': 'openaddresses',
'source_id': '123456',
'layer': 'address',
'address_parts': {}
},
{
'name': { 'default': '100 Main St' },
'source': 'openaddresses',
'source_id': '654321',
'layer': 'address',
'address_parts': {
'zip': '54321'
}
}
]
};

var expectedCount = 1;
dedupe(req, res, function () {
t.equal(res.data.length, expectedCount, 'results have fewer items than before');
t.deepEqual(res.data[0].source_id, '654321', 'openaddresses result with zip won');
t.end();
});
});
};

module.exports.all = function (tape, common) {
Expand Down