From 2398f05f8d96c3003f16a2124ff89961869a834c Mon Sep 17 00:00:00 2001 From: missinglink Date: Mon, 25 Apr 2016 13:33:08 +0200 Subject: [PATCH] fix borough matching for both autocomplete and search endpoints --- query/autocomplete.js | 1 + query/autocomplete_defaults.js | 4 ++++ query/search.js | 1 + query/text_parser.js | 1 + .../autocomplete_linguistic_with_admin.js | 9 +++++++++ .../autocomplete_single_character_street.js | 8 ++++++++ test/unit/fixture/search_full_address.js | 8 ++++++++ test/unit/fixture/search_partial_address.js | 8 ++++++++ test/unit/fixture/search_regions_address.js | 8 ++++++++ test/unit/query/search.js | 18 +++++++++--------- 10 files changed, 57 insertions(+), 9 deletions(-) diff --git a/query/autocomplete.js b/query/autocomplete.js index fec0a80b..6da4d569 100644 --- a/query/autocomplete.js +++ b/query/autocomplete.js @@ -34,6 +34,7 @@ query.score( peliasQuery.view.admin('country_a') ); query.score( peliasQuery.view.admin('region') ); query.score( peliasQuery.view.admin('region_a') ); query.score( peliasQuery.view.admin('county') ); +query.score( peliasQuery.view.admin('borough') ); query.score( peliasQuery.view.admin('localadmin') ); query.score( peliasQuery.view.admin('locality') ); query.score( peliasQuery.view.admin('neighbourhood') ); diff --git a/query/autocomplete_defaults.js b/query/autocomplete_defaults.js index 9c432cb9..8f46ce8d 100644 --- a/query/autocomplete_defaults.js +++ b/query/autocomplete_defaults.js @@ -82,6 +82,10 @@ module.exports = _.merge({}, peliasQuery.defaults, { 'admin:neighbourhood:field': 'parent.neighbourhood', 'admin:neighbourhood:boost': 200, + 'admin:borough:analyzer': 'peliasAdmin', + 'admin:borough:field': 'parent.borough', + 'admin:borough:boost': 800, + 'popularity:field': 'popularity', 'popularity:modifier': 'log1p', 'popularity:max_boost': 20, diff --git a/query/search.js b/query/search.js index 9f0a792c..77fcb3f5 100644 --- a/query/search.js +++ b/query/search.js @@ -30,6 +30,7 @@ query.score( peliasQuery.view.admin('country_a') ); query.score( peliasQuery.view.admin('region') ); query.score( peliasQuery.view.admin('region_a') ); query.score( peliasQuery.view.admin('county') ); +query.score( peliasQuery.view.admin('borough') ); query.score( peliasQuery.view.admin('localadmin') ); query.score( peliasQuery.view.admin('locality') ); query.score( peliasQuery.view.admin('neighbourhood') ); diff --git a/query/text_parser.js b/query/text_parser.js index d19465eb..914a7f43 100644 --- a/query/text_parser.js +++ b/query/text_parser.js @@ -9,6 +9,7 @@ or postalcode because we should only try to match those when we're sure that's w */ var adminFields = placeTypes.concat([ 'region_a', + 'borough' ]); /** diff --git a/test/unit/fixture/autocomplete_linguistic_with_admin.js b/test/unit/fixture/autocomplete_linguistic_with_admin.js index e3a62df2..a0b07025 100644 --- a/test/unit/fixture/autocomplete_linguistic_with_admin.js +++ b/test/unit/fixture/autocomplete_linguistic_with_admin.js @@ -54,6 +54,15 @@ module.exports = { } } }, + { + 'match': { + 'parent.borough': { + 'analyzer': 'peliasAdmin', + 'boost': 800, + 'query': 'three' + } + } + }, { 'match': { 'parent.localadmin': { diff --git a/test/unit/fixture/autocomplete_single_character_street.js b/test/unit/fixture/autocomplete_single_character_street.js index e992cc58..77264f8e 100644 --- a/test/unit/fixture/autocomplete_single_character_street.js +++ b/test/unit/fixture/autocomplete_single_character_street.js @@ -56,6 +56,14 @@ module.exports = { 'analyzer': 'peliasAdmin' } } + }, { + 'match': { + 'parent.borough': { + 'analyzer': 'peliasAdmin', + 'boost': 800, + 'query': 'laird' + } + } }, { 'match': { 'parent.localadmin': { diff --git a/test/unit/fixture/search_full_address.js b/test/unit/fixture/search_full_address.js index 172d439f..dfd64e34 100644 --- a/test/unit/fixture/search_full_address.js +++ b/test/unit/fixture/search_full_address.js @@ -139,6 +139,14 @@ module.exports = { 'analyzer': vs['admin:county:analyzer'] } } + }, { + 'match': { + 'parent.borough': { + 'query': 'new york', + 'boost': vs['admin:borough:boost'], + 'analyzer': vs['admin:borough:analyzer'] + } + } }, { 'match': { 'parent.localadmin': { diff --git a/test/unit/fixture/search_partial_address.js b/test/unit/fixture/search_partial_address.js index 6810de54..746899b7 100644 --- a/test/unit/fixture/search_partial_address.js +++ b/test/unit/fixture/search_partial_address.js @@ -107,6 +107,14 @@ module.exports = { 'analyzer': vs['admin:county:analyzer'] } } + }, { + 'match': { + 'parent.borough': { + 'query': 'new york', + 'boost': vs['admin:borough:boost'], + 'analyzer': vs['admin:borough:analyzer'] + } + } }, { 'match': { 'parent.localadmin': { diff --git a/test/unit/fixture/search_regions_address.js b/test/unit/fixture/search_regions_address.js index bf3f3dce..0a8b199d 100644 --- a/test/unit/fixture/search_regions_address.js +++ b/test/unit/fixture/search_regions_address.js @@ -123,6 +123,14 @@ module.exports = { 'analyzer': vs['admin:county:analyzer'] } } + }, { + 'match': { + 'parent.borough': { + 'query': 'manhattan', + 'boost': vs['admin:borough:boost'], + 'analyzer': vs['admin:borough:analyzer'] + } + } }, { 'match': { 'parent.localadmin': { diff --git a/test/unit/query/search.js b/test/unit/query/search.js index 426eb2bc..a2bb8e2f 100644 --- a/test/unit/query/search.js +++ b/test/unit/query/search.js @@ -25,7 +25,7 @@ module.exports.tests.query = function(test, common) { var compiled = JSON.parse( JSON.stringify( query ) ); var expected = require('../fixture/search_linguistic_focus_bbox'); - t.deepEqual(compiled, expected, 'valid search query'); + t.deepEqual(compiled, expected, 'search_linguistic_focus_bbox'); t.end(); }); @@ -42,7 +42,7 @@ module.exports.tests.query = function(test, common) { var compiled = JSON.parse( JSON.stringify( query ) ); var expected = require('../fixture/search_linguistic_bbox'); - t.deepEqual(compiled, expected, 'valid search query'); + t.deepEqual(compiled, expected, 'search_linguistic_bbox'); t.end(); }); @@ -55,7 +55,7 @@ module.exports.tests.query = function(test, common) { var compiled = JSON.parse( JSON.stringify( query ) ); var expected = require('../fixture/search_linguistic_only'); - t.deepEqual(compiled, expected, 'valid search query'); + t.deepEqual(compiled, expected, 'search_linguistic_only'); t.end(); }); @@ -69,7 +69,7 @@ module.exports.tests.query = function(test, common) { var compiled = JSON.parse( JSON.stringify( query ) ); var expected = require('../fixture/search_linguistic_focus'); - t.deepEqual(compiled, expected, 'valid search query'); + t.deepEqual(compiled, expected, 'search_linguistic_focus'); t.end(); }); @@ -86,7 +86,7 @@ module.exports.tests.query = function(test, common) { var compiled = JSON.parse( JSON.stringify( query ) ); var expected = require('../fixture/search_linguistic_viewport'); - t.deepEqual(compiled, expected, 'valid search query'); + t.deepEqual(compiled, expected, 'search_linguistic_viewport'); t.end(); }); @@ -119,7 +119,7 @@ module.exports.tests.query = function(test, common) { var compiled = JSON.parse( JSON.stringify( query ) ); var expected = require('../fixture/search_linguistic_focus_null_island'); - t.deepEqual(compiled, expected, 'valid search query'); + t.deepEqual(compiled, expected, 'search_linguistic_focus_null_island'); t.end(); }); @@ -134,7 +134,7 @@ module.exports.tests.query = function(test, common) { var compiled = JSON.parse( JSON.stringify( query ) ); var expected = require('../fixture/search_full_address'); - t.deepEqual(compiled, expected, 'valid search query'); + t.deepEqual(compiled, expected, 'search_full_address'); t.end(); }); @@ -149,7 +149,7 @@ module.exports.tests.query = function(test, common) { var compiled = JSON.parse( JSON.stringify( query ) ); var expected = require('../fixture/search_partial_address'); - t.deepEqual(compiled, expected, 'valid search query'); + t.deepEqual(compiled, expected, 'search_partial_address'); t.end(); }); @@ -164,7 +164,7 @@ module.exports.tests.query = function(test, common) { var compiled = JSON.parse( JSON.stringify( query ) ); var expected = require('../fixture/search_regions_address'); - t.deepEqual(compiled, expected, 'valid search query'); + t.deepEqual(compiled, expected, 'search_regions_address'); t.end(); });