From 355b70588c3d5f83d5ec63ce39cc765fa8536fe8 Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Tue, 21 Jan 2025 14:04:58 +0100 Subject: [PATCH] feat(query): improve unit number sorting for fallback.housenumber queries --- layout/AddressesUsingIdsQuery.js | 15 +++++++++++++++ layout/FallbackQuery.js | 12 ++++++++++-- layout/StructuredFallbackQuery.js | 18 +++++++++++++++--- .../housenumber_no_units.json | 9 +++++++++ .../addressesUsingIdsQuery/no_layers.json | 18 ++++++++++++++++++ .../no_layers_with_boosts.json | 9 +++++++++ .../addressesUsingIdsQuery/with_filters.json | 9 +++++++++ .../addressesUsingIdsQuery/with_layers.json | 9 +++++++++ .../with_layers_and_filters.json | 9 +++++++++ .../addressesUsingIdsQuery/with_scores.json | 9 +++++++++ test/fixtures/fallbackQuery1.json | 10 +++++++++- test/fixtures/fallbackQuery2.json | 10 +++++++++- .../fallbackQuery_address_with_postcode.json | 7 +++++++ .../structuredFallbackQuery/address.json | 10 +++++++++- .../address_with_postcode.json | 7 +++++++ .../structuredFallbackQuery/housenumber.json | 10 +++++++++- .../structuredFallbackQuery/query.json | 10 +++++++++- 17 files changed, 171 insertions(+), 10 deletions(-) diff --git a/layout/AddressesUsingIdsQuery.js b/layout/AddressesUsingIdsQuery.js index 682fe70..ca7ae5f 100644 --- a/layout/AddressesUsingIdsQuery.js +++ b/layout/AddressesUsingIdsQuery.js @@ -13,6 +13,11 @@ function createAddressShould(vs) { analyzer: vs.var('address:street:analyzer') }) ], + should: [ + // non-numeric tokens are stripped from the index, use the phrase field to improve sorting. + // see: https://github.com/pelias/pelias/issues/810 + match_phrase('phrase.default', vs.var('input:housenumber')) + ], filter: { term: { layer: 'address' @@ -40,6 +45,11 @@ function createUnitAndAddressShould(vs) { analyzer: vs.var('address:street:analyzer') }) ], + should: [ + // non-numeric tokens are stripped from the index, use the phrase field to improve sorting. + // see: https://github.com/pelias/pelias/issues/810 + match_phrase('phrase.default', vs.var('input:housenumber')) + ], filter: { term: { layer: 'address' @@ -67,6 +77,11 @@ function createPostcodeAndAddressShould(vs) { analyzer: vs.var('address:street:analyzer') }) ], + should: [ + // non-numeric tokens are stripped from the index, use the phrase field to improve sorting. + // see: https://github.com/pelias/pelias/issues/810 + match_phrase('phrase.default', vs.var('input:housenumber')) + ], filter: { term: { layer: 'address' diff --git a/layout/FallbackQuery.js b/layout/FallbackQuery.js index 7e5972e..86230bc 100644 --- a/layout/FallbackQuery.js +++ b/layout/FallbackQuery.js @@ -238,7 +238,11 @@ function addUnitAndHouseNumberAndStreet(vs) { analyzer: vs.var('address:street:analyzer') }) ], - should: [], + should: [ + // non-numeric tokens are stripped from the index, use the phrase field to improve sorting. + // see: https://github.com/pelias/pelias/issues/810 + match_phrase('phrase.default', vs.var('input:housenumber')) + ], filter: { term: { layer: 'address' @@ -273,7 +277,11 @@ function addHouseNumberAndStreet(vs) { analyzer: vs.var('address:street:analyzer') }) ], - should: [], + should: [ + // non-numeric tokens are stripped from the index, use the phrase field to improve sorting. + // see: https://github.com/pelias/pelias/issues/810 + match_phrase('phrase.default', vs.var('input:housenumber')) + ], filter: { term: { layer: 'address' diff --git a/layout/StructuredFallbackQuery.js b/layout/StructuredFallbackQuery.js index 7e21a39..86c80f3 100644 --- a/layout/StructuredFallbackQuery.js +++ b/layout/StructuredFallbackQuery.js @@ -194,7 +194,11 @@ function addUnitAndHouseNumberAndStreet(vs) { match_phrase('address_parts.number', vs.var('input:housenumber')), match_phrase('address_parts.street', vs.var('input:street'), { slop: vs.var('address:street:slop') }) ], - should: [], + should: [ + // non-numeric tokens are stripped from the index, use the phrase field to improve sorting. + // see: https://github.com/pelias/pelias/issues/810 + match_phrase('phrase.default', vs.var('input:housenumber')) + ], filter: { term: { layer: 'address' @@ -232,7 +236,11 @@ function addHouseNumber(vs) { } } ], - should: [], + should: [ + // non-numeric tokens are stripped from the index, use the phrase field to improve sorting. + // see: https://github.com/pelias/pelias/issues/810 + match_phrase('phrase.default', vs.var('input:housenumber')) + ], filter: { term: { layer: 'address' @@ -264,7 +272,11 @@ function addHouseNumberAndStreet(vs) { match_phrase('address_parts.number', vs.var('input:housenumber')), match_phrase('address_parts.street', vs.var('input:street'), { slop: vs.var('address:street:slop') }) ], - should: [], + should: [ + // non-numeric tokens are stripped from the index, use the phrase field to improve sorting. + // see: https://github.com/pelias/pelias/issues/810 + match_phrase('phrase.default', vs.var('input:housenumber')) + ], filter: { term: { layer: 'address' diff --git a/test/fixtures/addressesUsingIdsQuery/housenumber_no_units.json b/test/fixtures/addressesUsingIdsQuery/housenumber_no_units.json index aa959a7..1ae2787 100644 --- a/test/fixtures/addressesUsingIdsQuery/housenumber_no_units.json +++ b/test/fixtures/addressesUsingIdsQuery/housenumber_no_units.json @@ -43,6 +43,15 @@ } } ], + "should": [ + { + "match_phrase": { + "phrase.default": { + "query": "housenumber value" + } + } + } + ], "filter": { "term": { "layer": "address" diff --git a/test/fixtures/addressesUsingIdsQuery/no_layers.json b/test/fixtures/addressesUsingIdsQuery/no_layers.json index 22acc61..f98d971 100644 --- a/test/fixtures/addressesUsingIdsQuery/no_layers.json +++ b/test/fixtures/addressesUsingIdsQuery/no_layers.json @@ -50,6 +50,15 @@ } } ], + "should": [ + { + "match_phrase": { + "phrase.default": { + "query": "housenumber value" + } + } + } + ], "filter": { "term": { "layer": "address" @@ -83,6 +92,15 @@ } } ], + "should": [ + { + "match_phrase": { + "phrase.default": { + "query": "housenumber value" + } + } + } + ], "filter": { "term": { "layer": "address" diff --git a/test/fixtures/addressesUsingIdsQuery/no_layers_with_boosts.json b/test/fixtures/addressesUsingIdsQuery/no_layers_with_boosts.json index 3b67b77..daa0c1c 100644 --- a/test/fixtures/addressesUsingIdsQuery/no_layers_with_boosts.json +++ b/test/fixtures/addressesUsingIdsQuery/no_layers_with_boosts.json @@ -52,6 +52,15 @@ } } ], + "should": [ + { + "match_phrase": { + "phrase.default": { + "query": "housenumber value" + } + } + } + ], "filter": { "term": { "layer": "address" diff --git a/test/fixtures/addressesUsingIdsQuery/with_filters.json b/test/fixtures/addressesUsingIdsQuery/with_filters.json index 8746f4c..afde832 100644 --- a/test/fixtures/addressesUsingIdsQuery/with_filters.json +++ b/test/fixtures/addressesUsingIdsQuery/with_filters.json @@ -50,6 +50,15 @@ } } ], + "should": [ + { + "match_phrase": { + "phrase.default": { + "query": "housenumber value" + } + } + } + ], "filter": { "term": { "layer": "address" diff --git a/test/fixtures/addressesUsingIdsQuery/with_layers.json b/test/fixtures/addressesUsingIdsQuery/with_layers.json index 57fafb6..88dbccd 100644 --- a/test/fixtures/addressesUsingIdsQuery/with_layers.json +++ b/test/fixtures/addressesUsingIdsQuery/with_layers.json @@ -50,6 +50,15 @@ } } ], + "should": [ + { + "match_phrase": { + "phrase.default": { + "query": "housenumber value" + } + } + } + ], "filter": { "term": { "layer": "address" diff --git a/test/fixtures/addressesUsingIdsQuery/with_layers_and_filters.json b/test/fixtures/addressesUsingIdsQuery/with_layers_and_filters.json index 22695a3..d123b07 100644 --- a/test/fixtures/addressesUsingIdsQuery/with_layers_and_filters.json +++ b/test/fixtures/addressesUsingIdsQuery/with_layers_and_filters.json @@ -50,6 +50,15 @@ } } ], + "should": [ + { + "match_phrase": { + "phrase.default": { + "query": "housenumber value" + } + } + } + ], "filter": { "term": { "layer": "address" diff --git a/test/fixtures/addressesUsingIdsQuery/with_scores.json b/test/fixtures/addressesUsingIdsQuery/with_scores.json index 8b2caca..834c0e1 100644 --- a/test/fixtures/addressesUsingIdsQuery/with_scores.json +++ b/test/fixtures/addressesUsingIdsQuery/with_scores.json @@ -50,6 +50,15 @@ } } ], + "should": [ + { + "match_phrase": { + "phrase.default": { + "query": "housenumber value" + } + } + } + ], "filter": { "term": { "layer": "address" diff --git a/test/fixtures/fallbackQuery1.json b/test/fixtures/fallbackQuery1.json index 18ec92d..22c5023 100644 --- a/test/fixtures/fallbackQuery1.json +++ b/test/fixtures/fallbackQuery1.json @@ -189,7 +189,15 @@ } } ], - "should": [], + "should": [ + { + "match_phrase": { + "phrase.default": { + "query": "house number value" + } + } + } + ], "filter": { "term": { "layer": "address" diff --git a/test/fixtures/fallbackQuery2.json b/test/fixtures/fallbackQuery2.json index a62d02c..b7598c4 100644 --- a/test/fixtures/fallbackQuery2.json +++ b/test/fixtures/fallbackQuery2.json @@ -93,7 +93,15 @@ } } ], - "should": [], + "should": [ + { + "match_phrase": { + "phrase.default": { + "query": "house number value" + } + } + } + ], "filter": { "term": { "layer": "address" diff --git a/test/fixtures/fallbackQuery_address_with_postcode.json b/test/fixtures/fallbackQuery_address_with_postcode.json index 9ed3d3c..09fc8d6 100644 --- a/test/fixtures/fallbackQuery_address_with_postcode.json +++ b/test/fixtures/fallbackQuery_address_with_postcode.json @@ -26,6 +26,13 @@ } ], "should": [ + { + "match_phrase": { + "phrase.default": { + "query": "house number value" + } + } + }, { "match_phrase": { "address_parts.zip": { diff --git a/test/fixtures/structuredFallbackQuery/address.json b/test/fixtures/structuredFallbackQuery/address.json index 1602305..4d88599 100644 --- a/test/fixtures/structuredFallbackQuery/address.json +++ b/test/fixtures/structuredFallbackQuery/address.json @@ -100,7 +100,15 @@ } } ], - "should": [], + "should": [ + { + "match_phrase": { + "phrase.default": { + "query": "house number value" + } + } + } + ], "filter": { "term": { "layer": "address" diff --git a/test/fixtures/structuredFallbackQuery/address_with_postcode.json b/test/fixtures/structuredFallbackQuery/address_with_postcode.json index 65769db..59047dc 100644 --- a/test/fixtures/structuredFallbackQuery/address_with_postcode.json +++ b/test/fixtures/structuredFallbackQuery/address_with_postcode.json @@ -26,6 +26,13 @@ } ], "should": [ + { + "match_phrase": { + "phrase.default": { + "query": "house number value" + } + } + }, { "match_phrase": { "address_parts.zip": { diff --git a/test/fixtures/structuredFallbackQuery/housenumber.json b/test/fixtures/structuredFallbackQuery/housenumber.json index a692ec0..187d30f 100644 --- a/test/fixtures/structuredFallbackQuery/housenumber.json +++ b/test/fixtures/structuredFallbackQuery/housenumber.json @@ -18,7 +18,15 @@ } } ], - "should": [], + "should": [ + { + "match_phrase": { + "phrase.default": { + "query": "house number value" + } + } + } + ], "filter": { "term": { "layer": "address" diff --git a/test/fixtures/structuredFallbackQuery/query.json b/test/fixtures/structuredFallbackQuery/query.json index 17a7e35..39f71d7 100644 --- a/test/fixtures/structuredFallbackQuery/query.json +++ b/test/fixtures/structuredFallbackQuery/query.json @@ -183,7 +183,15 @@ } } ], - "should": [], + "should": [ + { + "match_phrase": { + "phrase.default": { + "query": "house number value" + } + } + } + ], "filter": { "term": { "layer": "address"