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

Adding address unit attribute to queries #77

Merged
merged 4 commits into from
Nov 20, 2017
Merged
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
3 changes: 2 additions & 1 deletion examples/all_the_things.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ q.score( query.view.phrase )
.score( query.view.focus( query.view.phrase ) );

// address components
q.score( query.view.address('housenumber') )
q.score( query.view.address('unit') )
.score( query.view.address('housenumber') )
.score( query.view.address('street') )
.score( query.view.address('postcode') );

Expand Down
5 changes: 5 additions & 0 deletions layout/AddressesUsingIdsQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ function createAddressShould(vs) {
bool: {
_name: 'fallback.address',
must: [
{
match_phrase: {
'address_parts.unit': vs.var('input:unit')
}
},
{
match_phrase: {
'address_parts.number': vs.var('input:housenumber')
Expand Down
51 changes: 50 additions & 1 deletion layout/FallbackQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,52 @@ function addQuery(vs) {

}

function addUnitAndHouseNumberAndStreet(vs) {
var o = {
bool: {
_name: 'fallback.address',
must: [
{
match_phrase: {
'address_parts.unit': vs.var('input:unit').toString()
}
},
{
match_phrase: {
'address_parts.number': vs.var('input:housenumber').toString()
}
},
{
match_phrase: {
'address_parts.street': vs.var('input:street').toString()
}
}
],
should: [],
filter: {
term: {
layer: 'address'
}
}
}
};

if (vs.isset('boost:address')) {
o.bool.boost = vs.var('boost:address');
}

addSecPostCode(vs, o);
addSecNeighbourhood(vs, o);
addSecBorough(vs, o);
addSecLocality(vs, o);
addSecCounty(vs, o);
addSecRegion(vs, o);
addSecCountry(vs, o);

return o;

}

function addHouseNumberAndStreet(vs) {
var o = {
bool: {
Expand Down Expand Up @@ -496,7 +542,10 @@ Layout.prototype.render = function( vs ){
if (vs.isset('input:query')) {
funcScoreShould.push(addQuery(vs));
}
if (vs.isset('input:housenumber') && vs.isset('input:street')) {
if (vs.isset('input:unit') && vs.isset('input:housenumber') && vs.isset('input:street')) {
funcScoreShould.push(addUnitAndHouseNumberAndStreet(vs));
}
else if (vs.isset('input:housenumber') && vs.isset('input:street')) {
funcScoreShould.push(addHouseNumberAndStreet(vs));
}
if (vs.isset('input:postcode')) {
Expand Down
50 changes: 49 additions & 1 deletion layout/StructuredFallbackQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,52 @@ function addQuery(vs) {

}

function addUnitAndHouseNumberAndStreet(vs) {
var o = {
bool: {
_name: 'fallback.address',
must: [
{
match_phrase: {
'address_parts.unit': vs.var('input:unit').toString()
}
},
{
match_phrase: {
'address_parts.number': vs.var('input:housenumber').toString()
}
},
{
match_phrase: {
'address_parts.street': vs.var('input:street').toString()
}
}
],
should: [],
filter: {
term: {
layer: 'address'
}
}
}
};

if (vs.isset('boost:address')) {
o.bool.boost = vs.var('boost:address');
}

addSecPostCode(vs, o);
addSecNeighbourhood(vs, o);
addSecBorough(vs, o);
addSecLocality(vs, o);
addSecCounty(vs, o);
addSecRegion(vs, o);
addSecCountry(vs, o);

return o;

}

function addHouseNumberAndStreet(vs) {
var o = {
bool: {
Expand Down Expand Up @@ -470,7 +516,9 @@ Layout.prototype.render = function( vs ){
funcScoreShould.push(addQuery(vs));
}
if (vs.isset('input:street')) {
if (vs.isset('input:housenumber')) {
if (vs.isset('input:unit') && vs.isset('input:housenumber')) {
funcScoreShould.push(addUnitAndHouseNumberAndStreet(vs));
} else if (vs.isset('input:housenumber')) {
funcScoreShould.push(addHouseNumberAndStreet(vs));
}
funcScoreShould.push(addStreet(vs));
Expand Down
5 changes: 5 additions & 0 deletions test/fixtures/addressesUsingIdsQuery/no_layers.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
"bool": {
"_name": "fallback.address",
"must": [
{
"match_phrase": {
"address_parts.unit": "unit value"
}
},
{
"match_phrase": {
"address_parts.number": "housenumber value"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@
"_name": "fallback.address",
"boost": 17,
"must": [
{
"match_phrase": {
"address_parts.unit": "unit value"
}
},
{
"match_phrase": {
"address_parts.number": "housenumber value"
Expand Down
5 changes: 5 additions & 0 deletions test/fixtures/addressesUsingIdsQuery/with_filters.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
"bool": {
"_name": "fallback.address",
"must": [
{
"match_phrase": {
"address_parts.unit": "unit value"
}
},
{
"match_phrase": {
"address_parts.number": "housenumber value"
Expand Down
5 changes: 5 additions & 0 deletions test/fixtures/addressesUsingIdsQuery/with_layers.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
"bool": {
"_name": "fallback.address",
"must": [
{
"match_phrase": {
"address_parts.unit": "unit value"
}
},
{
"match_phrase": {
"address_parts.number": "housenumber value"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
"bool": {
"_name": "fallback.address",
"must": [
{
"match_phrase": {
"address_parts.unit": "unit value"
}
},
{
"match_phrase": {
"address_parts.number": "housenumber value"
Expand Down
5 changes: 5 additions & 0 deletions test/fixtures/addressesUsingIdsQuery/with_scores.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
"bool": {
"_name": "fallback.address",
"must": [
{
"match_phrase": {
"address_parts.unit": "unit value"
}
},
{
"match_phrase": {
"address_parts.number": "housenumber value"
Expand Down
5 changes: 5 additions & 0 deletions test/fixtures/fallbackQuery1.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@
"_name": "fallback.address",
"boost": { "$": 19 },
"must": [
{
"match_phrase": {
"address_parts.unit": "unit value"
}
},
{
"match_phrase": {
"address_parts.number": "house number value"
Expand Down
5 changes: 5 additions & 0 deletions test/fixtures/structuredFallbackQuery/address.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
"_name": "fallback.address",
"boost": { "$": 19 },
"must": [
{
"match_phrase": {
"address_parts.unit": "unit value"
}
},
{
"match_phrase": {
"address_parts.number": "house number value"
Expand Down
6 changes: 6 additions & 0 deletions test/layout/AddressesUsingIdsQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module.exports.tests.base_render = (test, common) => {
const vs = new VariableStore();
vs.var('size', 'size value');
vs.var('track_scores', 'track_scores value');
vs.var('input:unit', 'unit value');
vs.var('input:housenumber', 'housenumber value');
vs.var('input:street', 'street value');

Expand All @@ -32,6 +33,7 @@ module.exports.tests.base_render = (test, common) => {
const vs = new VariableStore();
vs.var('size', 'size value');
vs.var('track_scores', 'track_scores value');
vs.var('input:unit', 'unit value');
vs.var('input:housenumber', 'housenumber value');
vs.var('input:street', 'street value');
vs.var('boost:address', 17);
Expand Down Expand Up @@ -75,6 +77,7 @@ module.exports.tests.base_render = (test, common) => {
const vs = new VariableStore();
vs.var('size', 'size value');
vs.var('track_scores', 'track_scores value');
vs.var('input:unit', 'unit value');
vs.var('input:housenumber', 'housenumber value');
vs.var('input:street', 'street value');
vs.var('input:layers', {
Expand Down Expand Up @@ -120,6 +123,7 @@ module.exports.tests.render_with_scores = (test, common) => {
const vs = new VariableStore();
vs.var('size', 'size value');
vs.var('track_scores', 'track_scores value');
vs.var('input:unit', 'unit value');
vs.var('input:housenumber', 'housenumber value');
vs.var('input:street', 'street value');

Expand Down Expand Up @@ -159,6 +163,7 @@ module.exports.tests.render_with_filters = (test, common) => {
const vs = new VariableStore();
vs.var('size', 'size value');
vs.var('track_scores', 'track_scores value');
vs.var('input:unit', 'unit value');
vs.var('input:housenumber', 'housenumber value');
vs.var('input:street', 'street value');

Expand Down Expand Up @@ -187,6 +192,7 @@ module.exports.tests.render_with_filters = (test, common) => {
const vs = new VariableStore();
vs.var('size', 'size value');
vs.var('track_scores', 'track_scores value');
vs.var('input:unit', 'unit value');
vs.var('input:housenumber', 'housenumber value');
vs.var('input:street', 'street value');
vs.var('input:layers', {
Expand Down
1 change: 1 addition & 0 deletions test/layout/FallbackQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ module.exports.tests.base_render = function(test, common) {
vs.var('size', 'size value');
vs.var('track_scores', 'track_scores value');
vs.var('input:query', 'query value');
vs.var('input:unit', 'unit value');
vs.var('input:housenumber', 'house number value');
vs.var('input:street', 'street value');
vs.var('input:neighbourhood', 'neighbourhood value');
Expand Down
1 change: 1 addition & 0 deletions test/layout/StructuredFallbackQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ module.exports.tests.base_render = function(test, common) {
var vs = new VariableStore();
vs.var('size', 'size value');
vs.var('track_scores', 'track_scores value');
vs.var('input:unit', 'unit value');
vs.var('input:housenumber', 'house number value');
vs.var('input:street', 'street value');
vs.var('input:neighbourhood', 'neighbourhood value');
Expand Down