Skip to content

Commit

Permalink
Merge pull request #135 from pelias/postcode-queries
Browse files Browse the repository at this point in the history
improve structured geocoding postcode matching
  • Loading branch information
missinglink authored Apr 16, 2024
2 parents a730d26 + 0c510a3 commit d4d293f
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 2 deletions.
3 changes: 2 additions & 1 deletion layout/StructuredFallbackQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,8 @@ function addPostCode(vs) {
vs.var('input:postcode').toString(),
'postalcode',
[
'parent.postalcode'
'parent.postalcode',
'address_parts.zip'
],
false
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,10 @@
"multi_match": {
"query": "postcode value",
"type": "phrase",
"fields": ["parent.postalcode"]
"fields": [
"parent.postalcode",
"address_parts.zip"
]
}
}
],
Expand Down
44 changes: 44 additions & 0 deletions test/fixtures/structuredFallbackQuery/postcode.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"query": {
"function_score": {
"query": {
"bool": {
"minimum_should_match": 1,
"should": [
{
"bool": {
"_name": "fallback.postalcode",
"must": [
{
"multi_match": {
"query": "postcode value",
"type": "phrase",
"fields": [
"parent.postalcode",
"address_parts.zip"
]
}
}
],
"filter": {
"term": {
"layer": "postalcode"
}
}
}
}
]
}
},
"max_boost": 20,
"functions": [],
"score_mode": "avg",
"boost_mode": "multiply"
}
},
"sort": [
"_score"
],
"size": "size value",
"track_scores": "track_scores value"
}
16 changes: 16 additions & 0 deletions test/layout/StructuredFallbackQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,22 @@ module.exports.tests.base_render = function(test, common) {

});

test('VariableStore with postcode only', function(t) {
var query = new StructuredFallbackQuery();

var vs = new VariableStore();
vs.var('size', 'size value');
vs.var('track_scores', 'track_scores value');
vs.var('input:postcode', 'postcode value');

var actual = JSON.parse(JSON.stringify(query.render(vs)));
var expected = require('../fixtures/structuredFallbackQuery/postcode.json');

t.deepEquals(actual, expected);
t.end();

});

test('VariableStore with address and less granular fields should include all others', function(t) {
var query = new StructuredFallbackQuery();

Expand Down

0 comments on commit d4d293f

Please sign in to comment.