Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

pelias-query

Package Overview
Dependencies
Maintainers
5
Versions
76
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pelias-query - npm Package Compare versions

Comparing version 8.5.0 to 8.6.0

layout/baseQuery.js

3

index.js

@@ -13,4 +13,7 @@

focus: require('./view/focus'),
focus_only_function: require('./view/focus_only_function'),
popularity: require('./view/popularity'),
population: require('./view/population'),
popularity_only_function: require('./view/popularity_only_function'),
population_only_function: require('./view/population_only_function'),
localregions: require('./view/localregions'),

@@ -17,0 +20,0 @@ ngrams: require('./view/ngrams'),

@@ -29,2 +29,5 @@ // This query is useful for specifying all the combinations of inputs starting

var _ = require('lodash');
var baseQuery = require('./baseQuery');
function Layout(){

@@ -35,4 +38,4 @@ this._score = [];

Layout.prototype.score = function( view, operator ){
this._score.push([ view, operator === 'must' ? 'must': 'should' ]);
Layout.prototype.score = function( view ){
this._score.push( view );
return this;

@@ -106,2 +109,14 @@ };

// add the postal code if supplied
function addSecPostCode(vs, o) {
// add postcode if specified
if (vs.isset('input:postcode')) {
o.bool.should.push({
match_phrase: {
'address_parts.zip': vs.var('input:postcode').toString()
}
});
}
}
function addSecNeighbourhood(vs, o) {

@@ -170,3 +185,5 @@ // add neighbourhood if specified

'parent.region',
'parent.region_a'
'parent.region_a',
'parent.macroregion',
'parent.macroregion_a'
]

@@ -230,2 +247,3 @@ ));

],
should: [],
filter: {

@@ -239,2 +257,3 @@ term: {

addSecPostCode(vs, o);
addSecNeighbourhood(vs, o);

@@ -251,2 +270,34 @@ addSecBorough(vs, o);

function addStreet(vs) {
var o = {
bool: {
_name: 'fallback.street',
must: [
{
match_phrase: {
'address_parts.street': vs.var('input:street').toString()
}
}
],
should: [],
filter: {
term: {
layer: 'street'
}
}
}
};
addSecPostCode(vs, o);
addSecNeighbourhood(vs, o);
addSecBorough(vs, o);
addSecLocality(vs, o);
addSecCounty(vs, o);
addSecRegion(vs, o);
addSecCountry(vs, o);
return o;
}
function addNeighbourhood(vs) {

@@ -305,2 +356,14 @@ var o = addPrimary(

function addLocalAdmin(vs) {
var o = addPrimary(vs.var('input:locality').toString(),
'localadmin', ['parent.localadmin', 'parent.localadmin_a'], false);
addSecCounty(vs, o);
addSecRegion(vs, o);
addSecCountry(vs, o);
return o;
}
function addCounty(vs) {

@@ -312,3 +375,19 @@ var o = addPrimary(

'parent.county',
'parent.county_a',
'parent.county_a'
],
false
);
addSecRegion(vs, o);
addSecCountry(vs, o);
return o;
}
function addMacroCounty(vs) {
var o = addPrimary(
vs.var('input:county').toString(),
'macrocounty',
[
'parent.macrocounty',

@@ -344,2 +423,34 @@ 'parent.macrocounty_a'

function addMacroRegion(vs) {
var o = addPrimary(
vs.var('input:region').toString(),
'macroregion',
[
'parent.macroregion',
'parent.macroregion_a'
],
true
);
addSecCountry(vs, o);
return o;
}
function addDependency(vs) {
var o = addPrimary(
vs.var('input:country').toString(),
'dependency',
[
'parent.dependency',
'parent.dependency_a'
],
true
);
return o;
}
function addCountry(vs) {

@@ -351,5 +462,3 @@ var o = addPrimary(

'parent.country',
'parent.country_a',
'parent.dependency',
'parent.dependency_a'
'parent.country_a'
],

@@ -366,25 +475,34 @@ true

var funcScoreShould = q.query.function_score.query.filtered.query.bool.should;
if (vs.isset('input:query')) {
q.query.bool.should.push(addQuery(vs));
funcScoreShould.push(addQuery(vs));
}
if (vs.isset('input:housenumber') && vs.isset('input:street')) {
q.query.bool.should.push(addHouseNumberAndStreet(vs));
funcScoreShould.push(addHouseNumberAndStreet(vs));
}
if (vs.isset('input:street')) {
funcScoreShould.push(addStreet(vs));
}
if (vs.isset('input:neighbourhood')) {
q.query.bool.should.push(addNeighbourhood(vs));
funcScoreShould.push(addNeighbourhood(vs));
}
if (vs.isset('input:borough')) {
q.query.bool.should.push(addBorough(vs));
funcScoreShould.push(addBorough(vs));
}
if (vs.isset('input:locality')) {
q.query.bool.should.push(addLocality(vs));
funcScoreShould.push(addLocality(vs));
funcScoreShould.push(addLocalAdmin(vs));
}
if (vs.isset('input:county')) {
q.query.bool.should.push(addCounty(vs));
funcScoreShould.push(addCounty(vs));
funcScoreShould.push(addMacroCounty(vs));
}
if (vs.isset('input:region')) {
q.query.bool.should.push(addRegion(vs));
funcScoreShould.push(addRegion(vs));
funcScoreShould.push(addMacroRegion(vs));
}
if (vs.isset('input:country')) {
q.query.bool.should.push(addCountry(vs));
funcScoreShould.push(addDependency(vs));
funcScoreShould.push(addCountry(vs));
}

@@ -394,10 +512,6 @@

if( this._score.length ){
this._score.forEach( function( condition ){
var view = condition[0], operator = condition[1];
this._score.forEach( function( view ){
var rendered = view( vs );
if( rendered ){
if( !q.query.bool.hasOwnProperty( operator ) ){
q.query.bool[ operator ] = [];
}
q.query.bool[ operator ].push( rendered );
q.query.function_score.functions.push( rendered );
}

@@ -412,6 +526,3 @@ });

if( rendered ){
if( !q.query.bool.hasOwnProperty( 'filter' ) ){
q.query.bool.filter = [];
}
q.query.bool.filter.push( rendered );
q.query.function_score.query.filtered.filter.bool.must.push( rendered );
}

@@ -425,13 +536,11 @@ });

Layout.base = function( vs ){
return {
query: {
bool: {
should: []
}
},
size: vs.var('size'),
track_scores: vs.var('track_scores')
};
var baseQueryCopy = _.cloneDeep(baseQuery);
baseQueryCopy.size = vs.var('size');
baseQueryCopy.track_scores = vs.var('track_scores');
return baseQueryCopy;
};
module.exports = Layout;

56

layout/GeodisambiguationQuery.js
// This query is useful for querying a value across a number of different
// layers when the analysis engine returns exactly 1 thing.
//
// For example, libpostal identifies "Luxembourg" to be a country whereas anyone
// For example, libpostal identifies 'Luxembourg' to be a country whereas anyone
// who's aware of the technical debt in Europe knows that there is a place named

@@ -40,2 +40,3 @@ // Luxembourg is legitimately all of the following:

var _ = require('lodash');
var baseQuery = require('./baseQuery');

@@ -47,4 +48,4 @@ function Layout(){

Layout.prototype.score = function( view, operator ){
this._score.push([ view, operator === 'must' ? 'must': 'should' ]);
Layout.prototype.score = function( view ){
this._score.push( view );
return this;

@@ -97,2 +98,3 @@ };

var q = Layout.base( vs );
var funcScoreShould = q.query.function_score.query.filtered.query.bool.should;

@@ -102,23 +104,19 @@ var coarse_value = getCoarseValue(vs);

// add coarse `should` query for each potential layer
q.query.bool.should.push(addCoarseLayer('neighbourhood', coarse_value));
q.query.bool.should.push(addCoarseLayer('borough', coarse_value));
q.query.bool.should.push(addCoarseLayer('locality', coarse_value));
q.query.bool.should.push(addCoarseLayer('localadmin', coarse_value));
q.query.bool.should.push(addCoarseLayer('county', coarse_value));
q.query.bool.should.push(addCoarseLayer('macrocounty', coarse_value));
q.query.bool.should.push(addCoarseLayer('region', coarse_value));
q.query.bool.should.push(addCoarseLayer('macroregion', coarse_value));
q.query.bool.should.push(addCoarseLayer('dependency', coarse_value));
q.query.bool.should.push(addCoarseLayer('country', coarse_value));
funcScoreShould.push(addCoarseLayer('neighbourhood', coarse_value));
funcScoreShould.push(addCoarseLayer('borough', coarse_value));
funcScoreShould.push(addCoarseLayer('locality', coarse_value));
funcScoreShould.push(addCoarseLayer('localadmin', coarse_value));
funcScoreShould.push(addCoarseLayer('county', coarse_value));
funcScoreShould.push(addCoarseLayer('macrocounty', coarse_value));
funcScoreShould.push(addCoarseLayer('region', coarse_value));
funcScoreShould.push(addCoarseLayer('macroregion', coarse_value));
funcScoreShould.push(addCoarseLayer('dependency', coarse_value));
funcScoreShould.push(addCoarseLayer('country', coarse_value));
// handle scoring views under 'query' section (both 'must' & 'should')
if( this._score.length ){
this._score.forEach( function( condition ){
var view = condition[0], operator = condition[1];
this._score.forEach( function( view ){
var rendered = view( vs );
if( rendered ){
if( !q.query.bool.hasOwnProperty( operator ) ){
q.query.bool[ operator ] = [];
}
q.query.bool[ operator ].push( rendered );
q.query.function_score.functions.push( rendered );
}

@@ -133,6 +131,3 @@ });

if( rendered ){
if( !q.query.bool.hasOwnProperty( 'filter' ) ){
q.query.bool.filter = [];
}
q.query.bool.filter.push( rendered );
q.query.function_score.query.filtered.filter.bool.must.push( rendered );
}

@@ -146,13 +141,10 @@ });

Layout.base = function( vs ){
return {
query: {
bool: {
should: []
}
},
size: vs.var('size'),
track_scores: vs.var('track_scores'),
};
var baseQueryCopy = _.cloneDeep(baseQuery);
baseQueryCopy.size = vs.var('size');
baseQueryCopy.track_scores = vs.var('track_scores');
return baseQueryCopy;
};
module.exports = Layout;
{
"name": "pelias-query",
"version": "8.5.0",
"version": "8.6.0",
"description": "An Elasticsearch query builder for Pelias",

@@ -5,0 +5,0 @@ "main": "index.js",

{
"query": {
"bool": {
"should": [
{
"bool": {
"_name": "fallback.venue",
"must": [
{
"multi_match": {
"query": "query value",
"type": "phrase",
"fields": [
"phrase.default"
]
}
},
{
"multi_match": {
"query": "neighbourhood value",
"type": "phrase",
"fields": [
"parent.neighbourhood",
"parent.neighbourhood_a"
]
}
},
{
"multi_match": {
"query": "borough value",
"type": "phrase",
"fields": [
"parent.borough",
"parent.borough_a"
]
}
},
{
"multi_match": {
"query": "locality value",
"type": "phrase",
"fields": [
"parent.locality",
"parent.locality_a",
"parent.localadmin",
"parent.localadmin_a"
]
}
},
{
"multi_match": {
"query": "county value",
"type": "phrase",
"fields": [
"parent.county",
"parent.county_a",
"parent.macrocounty",
"parent.macrocounty_a"
]
}
},
{
"multi_match": {
"query": "region value",
"type": "phrase",
"fields": [
"parent.region",
"parent.region_a"
]
}
},
{
"multi_match": {
"query": "country value",
"type": "phrase",
"fields": [
"parent.country",
"parent.country_a",
"parent.dependency",
"parent.dependency_a"
]
}
"function_score": {
"query": {
"filtered": {
"query": {
"bool": {
"should": [
{
"bool": {
"_name": "fallback.venue",
"must": [
{
"multi_match": {
"query": "query value",
"type": "phrase",
"fields": [
"phrase.default"
]
}
},
{
"multi_match": {
"query": "neighbourhood value",
"type": "phrase",
"fields": [
"parent.neighbourhood",
"parent.neighbourhood_a"
]
}
},
{
"multi_match": {
"query": "borough value",
"type": "phrase",
"fields": [
"parent.borough",
"parent.borough_a"
]
}
},
{
"multi_match": {
"query": "locality value",
"type": "phrase",
"fields": [
"parent.locality",
"parent.locality_a",
"parent.localadmin",
"parent.localadmin_a"
]
}
},
{
"multi_match": {
"query": "county value",
"type": "phrase",
"fields": [
"parent.county",
"parent.county_a",
"parent.macrocounty",
"parent.macrocounty_a"
]
}
},
{
"multi_match": {
"query": "region value",
"type": "phrase",
"fields": [
"parent.region",
"parent.region_a",
"parent.macroregion",
"parent.macroregion_a"
]
}
},
{
"multi_match": {
"query": "country value",
"type": "phrase",
"fields": [
"parent.country",
"parent.country_a",
"parent.dependency",
"parent.dependency_a"
]
}
}
],
"filter": {
"term": {
"layer": "venue"
}
}
}
},
{
"bool": {
"_name": "fallback.address",
"must": [
{
"match_phrase": {
"address_parts.number": "house number value"
}
},
{
"match_phrase": {
"address_parts.street": "street value"
}
},
{
"multi_match": {
"query": "neighbourhood value",
"type": "phrase",
"fields": [
"parent.neighbourhood",
"parent.neighbourhood_a"
]
}
},
{
"multi_match": {
"query": "borough value",
"type": "phrase",
"fields": [
"parent.borough",
"parent.borough_a"
]
}
},
{
"multi_match": {
"query": "locality value",
"type": "phrase",
"fields": [
"parent.locality",
"parent.locality_a",
"parent.localadmin",
"parent.localadmin_a"
]
}
},
{
"multi_match": {
"query": "county value",
"type": "phrase",
"fields": [
"parent.county",
"parent.county_a",
"parent.macrocounty",
"parent.macrocounty_a"
]
}
},
{
"multi_match": {
"query": "region value",
"type": "phrase",
"fields": [
"parent.region",
"parent.region_a",
"parent.macroregion",
"parent.macroregion_a"
]
}
},
{
"multi_match": {
"query": "country value",
"type": "phrase",
"fields": [
"parent.country",
"parent.country_a",
"parent.dependency",
"parent.dependency_a"
]
}
}
],
"should": [],
"filter": {
"term": {
"layer": "address"
}
}
}
},
{
"bool": {
"_name": "fallback.street",
"must": [
{
"match_phrase": {
"address_parts.street": "street value"
}
},
{
"multi_match": {
"query": "neighbourhood value",
"type": "phrase",
"fields": [
"parent.neighbourhood",
"parent.neighbourhood_a"
]
}
},
{
"multi_match": {
"query": "borough value",
"type": "phrase",
"fields": [
"parent.borough",
"parent.borough_a"
]
}
},
{
"multi_match": {
"query": "locality value",
"type": "phrase",
"fields": [
"parent.locality",
"parent.locality_a",
"parent.localadmin",
"parent.localadmin_a"
]
}
},
{
"multi_match": {
"query": "county value",
"type": "phrase",
"fields": [
"parent.county",
"parent.county_a",
"parent.macrocounty",
"parent.macrocounty_a"
]
}
},
{
"multi_match": {
"query": "region value",
"type": "phrase",
"fields": [
"parent.region",
"parent.region_a",
"parent.macroregion",
"parent.macroregion_a"
]
}
},
{
"multi_match": {
"query": "country value",
"type": "phrase",
"fields": [
"parent.country",
"parent.country_a",
"parent.dependency",
"parent.dependency_a"
]
}
}
],
"should": [],
"filter": {
"term": {
"layer": "street"
}
}
}
},
{
"bool": {
"_name": "fallback.neighbourhood",
"must": [
{
"multi_match": {
"query": "neighbourhood value",
"type": "phrase",
"fields": [
"parent.neighbourhood",
"parent.neighbourhood_a"
]
}
},
{
"multi_match": {
"query": "borough value",
"type": "phrase",
"fields": [
"parent.borough",
"parent.borough_a"
]
}
},
{
"multi_match": {
"query": "locality value",
"type": "phrase",
"fields": [
"parent.locality",
"parent.locality_a",
"parent.localadmin",
"parent.localadmin_a"
]
}
},
{
"multi_match": {
"query": "county value",
"type": "phrase",
"fields": [
"parent.county",
"parent.county_a",
"parent.macrocounty",
"parent.macrocounty_a"
]
}
},
{
"multi_match": {
"query": "region value",
"type": "phrase",
"fields": [
"parent.region",
"parent.region_a",
"parent.macroregion",
"parent.macroregion_a"
]
}
},
{
"multi_match": {
"query": "country value",
"type": "phrase",
"fields": [
"parent.country",
"parent.country_a",
"parent.dependency",
"parent.dependency_a"
]
}
}
],
"filter": {
"term": {
"layer": "neighbourhood"
}
}
}
},
{
"bool": {
"_name": "fallback.borough",
"must": [
{
"multi_match": {
"query": "borough value",
"type": "phrase",
"fields": [
"parent.borough",
"parent.borough_a"
]
}
},
{
"multi_match": {
"query": "locality value",
"type": "phrase",
"fields": [
"parent.locality",
"parent.locality_a",
"parent.localadmin",
"parent.localadmin_a"
]
}
},
{
"multi_match": {
"query": "county value",
"type": "phrase",
"fields": [
"parent.county",
"parent.county_a",
"parent.macrocounty",
"parent.macrocounty_a"
]
}
},
{
"multi_match": {
"query": "region value",
"type": "phrase",
"fields": [
"parent.region",
"parent.region_a",
"parent.macroregion",
"parent.macroregion_a"
]
}
},
{
"multi_match": {
"query": "country value",
"type": "phrase",
"fields": [
"parent.country",
"parent.country_a",
"parent.dependency",
"parent.dependency_a"
]
}
}
],
"filter": {
"term": {
"layer": "borough"
}
}
}
},
{
"bool": {
"_name": "fallback.locality",
"must": [
{
"multi_match": {
"query": "locality value",
"type": "phrase",
"fields": [
"parent.locality",
"parent.locality_a"
]
}
},
{
"multi_match": {
"query": "county value",
"type": "phrase",
"fields": [
"parent.county",
"parent.county_a",
"parent.macrocounty",
"parent.macrocounty_a"
]
}
},
{
"multi_match": {
"query": "region value",
"type": "phrase",
"fields": [
"parent.region",
"parent.region_a",
"parent.macroregion",
"parent.macroregion_a"
]
}
},
{
"multi_match": {
"query": "country value",
"type": "phrase",
"fields": [
"parent.country",
"parent.country_a",
"parent.dependency",
"parent.dependency_a"
]
}
}
],
"filter": {
"term": {
"layer": "locality"
}
}
}
},
{
"bool": {
"_name": "fallback.localadmin",
"must": [
{
"multi_match": {
"query": "locality value",
"type": "phrase",
"fields": [
"parent.localadmin",
"parent.localadmin_a"
]
}
},
{
"multi_match": {
"query": "county value",
"type": "phrase",
"fields": [
"parent.county",
"parent.county_a",
"parent.macrocounty",
"parent.macrocounty_a"
]
}
},
{
"multi_match": {
"query": "region value",
"type": "phrase",
"fields": [
"parent.region",
"parent.region_a",
"parent.macroregion",
"parent.macroregion_a"
]
}
},
{
"multi_match": {
"query": "country value",
"type": "phrase",
"fields": [
"parent.country",
"parent.country_a",
"parent.dependency",
"parent.dependency_a"
]
}
}
],
"filter": {
"term": {
"layer": "localadmin"
}
}
}
},
{
"bool": {
"_name": "fallback.county",
"must": [
{
"multi_match": {
"query": "county value",
"type": "phrase",
"fields": [
"parent.county",
"parent.county_a"
]
}
},
{
"multi_match": {
"query": "region value",
"type": "phrase",
"fields": [
"parent.region",
"parent.region_a",
"parent.macroregion",
"parent.macroregion_a"
]
}
},
{
"multi_match": {
"query": "country value",
"type": "phrase",
"fields": [
"parent.country",
"parent.country_a",
"parent.dependency",
"parent.dependency_a"
]
}
}
],
"filter": {
"term": {
"layer": "county"
}
}
}
},
{
"bool": {
"_name": "fallback.macrocounty",
"must": [
{
"multi_match": {
"query": "county value",
"type": "phrase",
"fields": [
"parent.macrocounty",
"parent.macrocounty_a"
]
}
},
{
"multi_match": {
"query": "region value",
"type": "phrase",
"fields": [
"parent.region",
"parent.region_a",
"parent.macroregion",
"parent.macroregion_a"
]
}
},
{
"multi_match": {
"query": "country value",
"type": "phrase",
"fields": [
"parent.country",
"parent.country_a",
"parent.dependency",
"parent.dependency_a"
]
}
}
],
"filter": {
"term": {
"layer": "macrocounty"
}
}
}
},
{
"bool": {
"_name": "fallback.region",
"must": [
{
"multi_match": {
"query": "region value",
"type": "phrase",
"fields": [
"parent.region",
"parent.region_a"
]
}
},
{
"multi_match": {
"query": "country value",
"type": "phrase",
"fields": [
"parent.country",
"parent.country_a",
"parent.dependency",
"parent.dependency_a"
]
}
}
],
"filter": {
"term": {
"layer": "region"
}
}
}
},
{
"bool": {
"_name": "fallback.macroregion",
"must": [
{
"multi_match": {
"query": "region value",
"type": "phrase",
"fields": [
"parent.macroregion",
"parent.macroregion_a"
]
}
},
{
"multi_match": {
"query": "country value",
"type": "phrase",
"fields": [
"parent.country",
"parent.country_a",
"parent.dependency",
"parent.dependency_a"
]
}
}
],
"filter": {
"term": {
"layer": "macroregion"
}
}
}
},
{
"bool": {
"_name": "fallback.dependency",
"must": [
{
"multi_match": {
"query": "country value",
"type": "phrase",
"fields": [
"parent.dependency",
"parent.dependency_a"
]
}
}
],
"filter": {
"term": {
"layer": "dependency"
}
}
}
},
{
"bool": {
"_name": "fallback.country",
"must": [
{
"multi_match": {
"query": "country value",
"type": "phrase",
"fields": [
"parent.country",
"parent.country_a"
]
}
}
],
"filter": {
"term": {
"layer": "country"
}
}
}
}
]
}
],
},
"filter": {
"term": {
"layer": "venue"
"bool": {
"must": []
}

@@ -92,401 +755,23 @@ }

},
{
"bool": {
"_name": "fallback.address",
"must": [
{
"match_phrase": {
"address_parts.number": "house number value"
}
},
{
"match_phrase": {
"address_parts.street": "street value"
}
},
{
"multi_match": {
"query": "neighbourhood value",
"type": "phrase",
"fields": [
"parent.neighbourhood",
"parent.neighbourhood_a"
]
}
},
{
"multi_match": {
"query": "borough value",
"type": "phrase",
"fields": [
"parent.borough",
"parent.borough_a"
]
}
},
{
"multi_match": {
"query": "locality value",
"type": "phrase",
"fields": [
"parent.locality",
"parent.locality_a",
"parent.localadmin",
"parent.localadmin_a"
]
}
},
{
"multi_match": {
"query": "county value",
"type": "phrase",
"fields": [
"parent.county",
"parent.county_a",
"parent.macrocounty",
"parent.macrocounty_a"
]
}
},
{
"multi_match": {
"query": "region value",
"type": "phrase",
"fields": [
"parent.region",
"parent.region_a"
]
}
},
{
"multi_match": {
"query": "country value",
"type": "phrase",
"fields": [
"parent.country",
"parent.country_a",
"parent.dependency",
"parent.dependency_a"
]
}
}
],
"filter": {
"term": {
"layer": "address"
}
}
}
},
{
"bool": {
"_name": "fallback.neighbourhood",
"must": [
{
"multi_match": {
"query": "neighbourhood value",
"type": "phrase",
"fields": [
"parent.neighbourhood",
"parent.neighbourhood_a"
]
}
},
{
"multi_match": {
"query": "borough value",
"type": "phrase",
"fields": [
"parent.borough",
"parent.borough_a"
]
}
},
{
"multi_match": {
"query": "locality value",
"type": "phrase",
"fields": [
"parent.locality",
"parent.locality_a",
"parent.localadmin",
"parent.localadmin_a"
]
}
},
{
"multi_match": {
"query": "county value",
"type": "phrase",
"fields": [
"parent.county",
"parent.county_a",
"parent.macrocounty",
"parent.macrocounty_a"
]
}
},
{
"multi_match": {
"query": "region value",
"type": "phrase",
"fields": [
"parent.region",
"parent.region_a"
]
}
},
{
"multi_match": {
"query": "country value",
"type": "phrase",
"fields": [
"parent.country",
"parent.country_a",
"parent.dependency",
"parent.dependency_a"
]
}
}
],
"filter": {
"term": {
"layer": "neighbourhood"
}
}
}
},
{
"bool": {
"_name": "fallback.borough",
"must": [
{
"multi_match": {
"query": "borough value",
"type": "phrase",
"fields": [
"parent.borough",
"parent.borough_a"
]
}
},
{
"multi_match": {
"query": "locality value",
"type": "phrase",
"fields": [
"parent.locality",
"parent.locality_a",
"parent.localadmin",
"parent.localadmin_a"
]
}
},
{
"multi_match": {
"query": "county value",
"type": "phrase",
"fields": [
"parent.county",
"parent.county_a",
"parent.macrocounty",
"parent.macrocounty_a"
]
}
},
{
"multi_match": {
"query": "region value",
"type": "phrase",
"fields": [
"parent.region",
"parent.region_a"
]
}
},
{
"multi_match": {
"query": "country value",
"type": "phrase",
"fields": [
"parent.country",
"parent.country_a",
"parent.dependency",
"parent.dependency_a"
]
}
}
],
"filter": {
"term": {
"layer": "borough"
}
}
}
},
{
"bool": {
"_name": "fallback.locality",
"must": [
{
"multi_match": {
"query": "locality value",
"type": "phrase",
"fields": [
"parent.locality",
"parent.locality_a"
]
}
},
{
"multi_match": {
"query": "county value",
"type": "phrase",
"fields": [
"parent.county",
"parent.county_a",
"parent.macrocounty",
"parent.macrocounty_a"
]
}
},
{
"multi_match": {
"query": "region value",
"type": "phrase",
"fields": [
"parent.region",
"parent.region_a"
]
}
},
{
"multi_match": {
"query": "country value",
"type": "phrase",
"fields": [
"parent.country",
"parent.country_a",
"parent.dependency",
"parent.dependency_a"
]
}
}
],
"filter": {
"term": {
"layer": "locality"
}
}
}
},
{
"bool": {
"_name": "fallback.county",
"must": [
{
"multi_match": {
"query": "county value",
"type": "phrase",
"fields": [
"parent.county",
"parent.county_a",
"parent.macrocounty",
"parent.macrocounty_a"
]
}
},
{
"multi_match": {
"query": "region value",
"type": "phrase",
"fields": [
"parent.region",
"parent.region_a"
]
}
},
{
"multi_match": {
"query": "country value",
"type": "phrase",
"fields": [
"parent.country",
"parent.country_a",
"parent.dependency",
"parent.dependency_a"
]
}
}
],
"filter": {
"term": {
"layer": "county"
}
}
}
},
{
"bool": {
"_name": "fallback.region",
"must": [
{
"multi_match": {
"query": "region value",
"type": "phrase",
"fields": [
"parent.region",
"parent.region_a"
]
}
},
{
"multi_match": {
"query": "country value",
"type": "phrase",
"fields": [
"parent.country",
"parent.country_a",
"parent.dependency",
"parent.dependency_a"
]
}
}
],
"filter": {
"term": {
"layer": "region"
}
}
}
},
{
"bool": {
"_name": "fallback.country",
"must": [
{
"multi_match": {
"query": "country value",
"type": "phrase",
"fields": [
"parent.country",
"parent.country_a",
"parent.dependency",
"parent.dependency_a"
]
}
}
],
"filter": {
"term": {
"layer": "country"
}
}
}
"max_boost": 20,
"functions": [],
"score_mode": "avg",
"boost_mode": "multiply"
}
},
"size": { "$": "size value" },
"track_scores": { "$": "track_scores value" },
"sort": [
{
"population": {
"order": "desc"
}
]
}
},
"size": { "$": "size value" },
"track_scores": { "$": "track_scores value" }
}
},
{
"popularity": {
"order": "desc"
}
},
"_score"
]
}
{
"query": {
"bool": {
"should": [
{
"bool": {
"_name": "fallback.address",
"must": [
{
"match_phrase": {
"address_parts.number": "house number value"
"function_score": {
"query": {
"filtered": {
"query": {
"bool": {
"should": [
{
"bool": {
"_name": "fallback.address",
"must": [
{
"match_phrase": {
"address_parts.number": "house number value"
}
},
{
"match_phrase": {
"address_parts.street": "street value"
}
},
{
"multi_match": {
"query": "neighbourhood value",
"type": "phrase",
"fields": [
"parent.neighbourhood",
"parent.neighbourhood_a"
]
}
},
{
"multi_match": {
"query": "borough value",
"type": "phrase",
"fields": [
"parent.borough",
"parent.borough_a"
]
}
},
{
"multi_match": {
"query": "locality value",
"type": "phrase",
"fields": [
"parent.locality",
"parent.locality_a",
"parent.localadmin",
"parent.localadmin_a"
]
}
},
{
"multi_match": {
"query": "county value",
"type": "phrase",
"fields": [
"parent.county",
"parent.county_a",
"parent.macrocounty",
"parent.macrocounty_a"
]
}
},
{
"multi_match": {
"query": "region value",
"type": "phrase",
"fields": [
"parent.region",
"parent.region_a",
"parent.macroregion",
"parent.macroregion_a"
]
}
},
{
"multi_match": {
"query": "country value",
"type": "phrase",
"fields": [
"parent.country",
"parent.country_a",
"parent.dependency",
"parent.dependency_a"
]
}
}
],
"should": [],
"filter": {
"term": {
"layer": "address"
}
}
}
},
{
"bool": {
"_name": "fallback.street",
"must": [
{
"match_phrase": {
"address_parts.street": "street value"
}
},
{
"multi_match": {
"query": "neighbourhood value",
"type": "phrase",
"fields": [
"parent.neighbourhood",
"parent.neighbourhood_a"
]
}
},
{
"multi_match": {
"query": "borough value",
"type": "phrase",
"fields": [
"parent.borough",
"parent.borough_a"
]
}
},
{
"multi_match": {
"query": "locality value",
"type": "phrase",
"fields": [
"parent.locality",
"parent.locality_a",
"parent.localadmin",
"parent.localadmin_a"
]
}
},
{
"multi_match": {
"query": "county value",
"type": "phrase",
"fields": [
"parent.county",
"parent.county_a",
"parent.macrocounty",
"parent.macrocounty_a"
]
}
},
{
"multi_match": {
"query": "region value",
"type": "phrase",
"fields": [
"parent.region",
"parent.region_a",
"parent.macroregion",
"parent.macroregion_a"
]
}
},
{
"multi_match": {
"query": "country value",
"type": "phrase",
"fields": [
"parent.country",
"parent.country_a",
"parent.dependency",
"parent.dependency_a"
]
}
}
],
"should": [],
"filter": {
"term": {
"layer": "street"
}
}
}
},
{
"bool": {
"_name": "fallback.neighbourhood",
"must": [
{
"multi_match": {
"query": "neighbourhood value",
"type": "phrase",
"fields": [
"parent.neighbourhood",
"parent.neighbourhood_a"
]
}
},
{
"multi_match": {
"query": "borough value",
"type": "phrase",
"fields": [
"parent.borough",
"parent.borough_a"
]
}
},
{
"multi_match": {
"query": "locality value",
"type": "phrase",
"fields": [
"parent.locality",
"parent.locality_a",
"parent.localadmin",
"parent.localadmin_a"
]
}
},
{
"multi_match": {
"query": "county value",
"type": "phrase",
"fields": [
"parent.county",
"parent.county_a",
"parent.macrocounty",
"parent.macrocounty_a"
]
}
},
{
"multi_match": {
"query": "region value",
"type": "phrase",
"fields": [
"parent.region",
"parent.region_a",
"parent.macroregion",
"parent.macroregion_a"
]
}
},
{
"multi_match": {
"query": "country value",
"type": "phrase",
"fields": [
"parent.country",
"parent.country_a",
"parent.dependency",
"parent.dependency_a"
]
}
}
],
"filter": {
"term": {
"layer": "neighbourhood"
}
}
}
},
{
"bool": {
"_name": "fallback.borough",
"must": [
{
"multi_match": {
"query": "borough value",
"type": "phrase",
"fields": [
"parent.borough",
"parent.borough_a"
]
}
},
{
"multi_match": {
"query": "locality value",
"type": "phrase",
"fields": [
"parent.locality",
"parent.locality_a",
"parent.localadmin",
"parent.localadmin_a"
]
}
},
{
"multi_match": {
"query": "county value",
"type": "phrase",
"fields": [
"parent.county",
"parent.county_a",
"parent.macrocounty",
"parent.macrocounty_a"
]
}
},
{
"multi_match": {
"query": "region value",
"type": "phrase",
"fields": [
"parent.region",
"parent.region_a",
"parent.macroregion",
"parent.macroregion_a"
]
}
},
{
"multi_match": {
"query": "country value",
"type": "phrase",
"fields": [
"parent.country",
"parent.country_a",
"parent.dependency",
"parent.dependency_a"
]
}
}
],
"filter": {
"term": {
"layer": "borough"
}
}
}
},
{
"bool": {
"_name": "fallback.locality",
"must": [
{
"multi_match": {
"query": "locality value",
"type": "phrase",
"fields": [
"parent.locality",
"parent.locality_a"
]
}
},
{
"multi_match": {
"query": "county value",
"type": "phrase",
"fields": [
"parent.county",
"parent.county_a",
"parent.macrocounty",
"parent.macrocounty_a"
]
}
},
{
"multi_match": {
"query": "region value",
"type": "phrase",
"fields": [
"parent.region",
"parent.region_a",
"parent.macroregion",
"parent.macroregion_a"
]
}
},
{
"multi_match": {
"query": "country value",
"type": "phrase",
"fields": [
"parent.country",
"parent.country_a",
"parent.dependency",
"parent.dependency_a"
]
}
}
],
"filter": {
"term": {
"layer": "locality"
}
}
}
},
{
"bool": {
"_name": "fallback.localadmin",
"must": [
{
"multi_match": {
"query": "locality value",
"type": "phrase",
"fields": [
"parent.localadmin",
"parent.localadmin_a"
]
}
},
{
"multi_match": {
"query": "county value",
"type": "phrase",
"fields": [
"parent.county",
"parent.county_a",
"parent.macrocounty",
"parent.macrocounty_a"
]
}
},
{
"multi_match": {
"query": "region value",
"type": "phrase",
"fields": [
"parent.region",
"parent.region_a",
"parent.macroregion",
"parent.macroregion_a"
]
}
},
{
"multi_match": {
"query": "country value",
"type": "phrase",
"fields": [
"parent.country",
"parent.country_a",
"parent.dependency",
"parent.dependency_a"
]
}
}
],
"filter": {
"term": {
"layer": "localadmin"
}
}
}
},
{
"bool": {
"_name": "fallback.county",
"must": [
{
"multi_match": {
"query": "county value",
"type": "phrase",
"fields": [
"parent.county",
"parent.county_a"
]
}
},
{
"multi_match": {
"query": "region value",
"type": "phrase",
"fields": [
"parent.region",
"parent.region_a",
"parent.macroregion",
"parent.macroregion_a"
]
}
},
{
"multi_match": {
"query": "country value",
"type": "phrase",
"fields": [
"parent.country",
"parent.country_a",
"parent.dependency",
"parent.dependency_a"
]
}
}
],
"filter": {
"term": {
"layer": "county"
}
}
}
},
{
"bool": {
"_name": "fallback.macrocounty",
"must": [
{
"multi_match": {
"query": "county value",
"type": "phrase",
"fields": [
"parent.macrocounty",
"parent.macrocounty_a"
]
}
},
{
"multi_match": {
"query": "region value",
"type": "phrase",
"fields": [
"parent.region",
"parent.region_a",
"parent.macroregion",
"parent.macroregion_a"
]
}
},
{
"multi_match": {
"query": "country value",
"type": "phrase",
"fields": [
"parent.country",
"parent.country_a",
"parent.dependency",
"parent.dependency_a"
]
}
}
],
"filter": {
"term": {
"layer": "macrocounty"
}
}
}
},
{
"bool": {
"_name": "fallback.region",
"must": [
{
"multi_match": {
"query": "region value",
"type": "phrase",
"fields": [
"parent.region",
"parent.region_a"
]
}
},
{
"multi_match": {
"query": "country value",
"type": "phrase",
"fields": [
"parent.country",
"parent.country_a",
"parent.dependency",
"parent.dependency_a"
]
}
}
],
"filter": {
"term": {
"layer": "region"
}
}
}
},
{
"bool": {
"_name": "fallback.macroregion",
"must": [
{
"multi_match": {
"query": "region value",
"type": "phrase",
"fields": [
"parent.macroregion",
"parent.macroregion_a"
]
}
},
{
"multi_match": {
"query": "country value",
"type": "phrase",
"fields": [
"parent.country",
"parent.country_a",
"parent.dependency",
"parent.dependency_a"
]
}
}
],
"filter": {
"term": {
"layer": "macroregion"
}
}
}
},
{
"bool": {
"_name": "fallback.dependency",
"must": [
{
"multi_match": {
"query": "country value",
"type": "phrase",
"fields": [
"parent.dependency",
"parent.dependency_a"
]
}
}
],
"filter": {
"term": {
"layer": "dependency"
}
}
}
},
{
"bool": {
"_name": "fallback.country",
"must": [
{
"multi_match": {
"query": "country value",
"type": "phrase",
"fields": [
"parent.country",
"parent.country_a"
]
}
}
],
"filter": {
"term": {
"layer": "country"
}
}
}
}
},
{
"match_phrase": {
"address_parts.street": "street value"
}
},
{
"multi_match": {
"query": "neighbourhood value",
"type": "phrase",
"fields": [
"parent.neighbourhood",
"parent.neighbourhood_a"
]
}
},
{
"multi_match": {
"query": "borough value",
"type": "phrase",
"fields": [
"parent.borough",
"parent.borough_a"
]
}
},
{
"multi_match": {
"query": "locality value",
"type": "phrase",
"fields": [
"parent.locality",
"parent.locality_a",
"parent.localadmin",
"parent.localadmin_a"
]
}
},
{
"multi_match": {
"query": "county value",
"type": "phrase",
"fields": [
"parent.county",
"parent.county_a",
"parent.macrocounty",
"parent.macrocounty_a"
]
}
},
{
"multi_match": {
"query": "region value",
"type": "phrase",
"fields": [
"parent.region",
"parent.region_a"
]
}
},
{
"multi_match": {
"query": "country value",
"type": "phrase",
"fields": [
"parent.country",
"parent.country_a",
"parent.dependency",
"parent.dependency_a"
]
}
}
],
"filter": {
"term": {
"layer": "address"
}
]
}
}
},
{
"bool": {
"_name": "fallback.neighbourhood",
"must": [
{
"multi_match": {
"query": "neighbourhood value",
"type": "phrase",
"fields": [
"parent.neighbourhood",
"parent.neighbourhood_a"
]
}
},
{
"multi_match": {
"query": "borough value",
"type": "phrase",
"fields": [
"parent.borough",
"parent.borough_a"
]
}
},
{
"multi_match": {
"query": "locality value",
"type": "phrase",
"fields": [
"parent.locality",
"parent.locality_a",
"parent.localadmin",
"parent.localadmin_a"
]
}
},
{
"multi_match": {
"query": "county value",
"type": "phrase",
"fields": [
"parent.county",
"parent.county_a",
"parent.macrocounty",
"parent.macrocounty_a"
]
}
},
{
"multi_match": {
"query": "region value",
"type": "phrase",
"fields": [
"parent.region",
"parent.region_a"
]
}
},
{
"multi_match": {
"query": "country value",
"type": "phrase",
"fields": [
"parent.country",
"parent.country_a",
"parent.dependency",
"parent.dependency_a"
]
}
}
],
"filter": {
"term": {
"layer": "neighbourhood"
}
},
"filter": {
"bool": {
"must": []
}
}
},
{
"bool": {
"_name": "fallback.borough",
"must": [
{
"multi_match": {
"query": "borough value",
"type": "phrase",
"fields": [
"parent.borough",
"parent.borough_a"
]
}
},
{
"multi_match": {
"query": "locality value",
"type": "phrase",
"fields": [
"parent.locality",
"parent.locality_a",
"parent.localadmin",
"parent.localadmin_a"
]
}
},
{
"multi_match": {
"query": "county value",
"type": "phrase",
"fields": [
"parent.county",
"parent.county_a",
"parent.macrocounty",
"parent.macrocounty_a"
]
}
},
{
"multi_match": {
"query": "region value",
"type": "phrase",
"fields": [
"parent.region",
"parent.region_a"
]
}
},
{
"multi_match": {
"query": "country value",
"type": "phrase",
"fields": [
"parent.country",
"parent.country_a",
"parent.dependency",
"parent.dependency_a"
]
}
}
],
"filter": {
"term": {
"layer": "borough"
}
}
}
},
{
"bool": {
"_name": "fallback.locality",
"must": [
{
"multi_match": {
"query": "locality value",
"type": "phrase",
"fields": [
"parent.locality",
"parent.locality_a"
]
}
},
{
"multi_match": {
"query": "county value",
"type": "phrase",
"fields": [
"parent.county",
"parent.county_a",
"parent.macrocounty",
"parent.macrocounty_a"
]
}
},
{
"multi_match": {
"query": "region value",
"type": "phrase",
"fields": [
"parent.region",
"parent.region_a"
]
}
},
{
"multi_match": {
"query": "country value",
"type": "phrase",
"fields": [
"parent.country",
"parent.country_a",
"parent.dependency",
"parent.dependency_a"
]
}
}
],
"filter": {
"term": {
"layer": "locality"
}
}
}
},
{
"bool": {
"_name": "fallback.county",
"must": [
{
"multi_match": {
"query": "county value",
"type": "phrase",
"fields": [
"parent.county",
"parent.county_a",
"parent.macrocounty",
"parent.macrocounty_a"
]
}
},
{
"multi_match": {
"query": "region value",
"type": "phrase",
"fields": [
"parent.region",
"parent.region_a"
]
}
},
{
"multi_match": {
"query": "country value",
"type": "phrase",
"fields": [
"parent.country",
"parent.country_a",
"parent.dependency",
"parent.dependency_a"
]
}
}
],
"filter": {
"term": {
"layer": "county"
}
}
}
},
{
"bool": {
"_name": "fallback.region",
"must": [
{
"multi_match": {
"query": "region value",
"type": "phrase",
"fields": [
"parent.region",
"parent.region_a"
]
}
},
{
"multi_match": {
"query": "country value",
"type": "phrase",
"fields": [
"parent.country",
"parent.country_a",
"parent.dependency",
"parent.dependency_a"
]
}
}
],
"filter": {
"term": {
"layer": "region"
}
}
}
},
{
"bool": {
"_name": "fallback.country",
"must": [
{
"multi_match": {
"query": "country value",
"type": "phrase",
"fields": [
"parent.country",
"parent.country_a",
"parent.dependency",
"parent.dependency_a"
]
}
}
],
"filter": {
"term": {
"layer": "country"
}
}
}
}
]
},
"max_boost": 20,
"functions": [],
"score_mode": "avg",
"boost_mode": "multiply"
}
},
"size": {
"$": "size value"
},
"track_scores": {
"$": "track_scores value"
}
}
"size": { "$": "size value" },
"track_scores": { "$": "track_scores value" },
"sort": [
{
"population": {
"order": "desc"
}
},
{
"popularity": {
"order": "desc"
}
},
"_score"
]
}

@@ -16,13 +16,4 @@ var FallbackQuery = require('../../layout/FallbackQuery');

var actual = query.render(vs);
var expected = require('../fixtures/fallbackQuery_nothing_set.json');
var expected = {
query: {
bool: {
should: []
}
},
size: { $: 'size value' },
track_scores: { $: 'track_scores value' }
};
t.deepEquals(actual, expected);

@@ -42,33 +33,4 @@ t.end();

var actual = query.render(vs);
var expected = require('../fixtures/fallbackQuery_neighbourhood_only.json');
var expected = {
query: {
bool: {
should: [
{
bool: {
_name: 'fallback.neighbourhood',
must: [
{
multi_match: {
query: 'neighbourhood value',
type: 'phrase',
fields: ['parent.neighbourhood', 'parent.neighbourhood_a']
}
}
],
filter: {
term: {
layer: 'neighbourhood'
}
}
}
}
]
}
},
size: { $: 'size value' },
track_scores: { $: 'track_scores value' }
};
t.deepEquals(actual, expected);

@@ -126,31 +88,4 @@ t.end();

};
module.exports.tests.scores = function(test, common) {
test('score with operator specified should be honored and in order', function(t) {
var score_view1 = function(vs) {
console.assert(vs !== null);
return { 'score field 1': 'score value 1' };
};
var score_view2 = function(vs) {
console.assert(vs !== null);
return { 'score field 2': 'score value 2' };
};
var score_view3 = function(vs) {
console.assert(vs !== null);
return { 'score field 3': 'score value 3' };
};
var score_view4 = function(vs) {
console.assert(vs !== null);
return { 'score field 4': 'score value 4' };
};
test('input:postcode set should include it at the address layer query', function(t) {
var query = new FallbackQuery();
query.score(score_view1, 'must');
query.score(score_view2, 'should');
query.score(score_view3, 'must');
query.score(score_view4, 'should');

@@ -160,54 +95,11 @@ var vs = new VariableStore();

vs.var('track_scores', 'track_scores value');
vs.var('input:housenumber', 'house number value');
vs.var('input:street', 'street value');
vs.var('input:postcode', 'postcode value');
var actual = query.render(vs);
var fs = require('fs');
var expected = {
query: {
bool: {
should: [
{ 'score field 2': 'score value 2'},
{ 'score field 4': 'score value 4'}
],
must: [
{ 'score field 1': 'score value 1'},
{ 'score field 3': 'score value 3'}
]
}
},
size: { $: 'size value' },
track_scores: { $: 'track_scores value' }
};
t.deepEquals(actual, expected);
t.end();
});
test('score without operator specified should be added as \'should\'', function(t) {
var score_view = function(vs) {
console.assert(vs !== null);
return { 'score field': 'score value' };
};
var query = new FallbackQuery();
query.score(score_view);
var vs = new VariableStore();
vs.var('size', 'size value');
vs.var('track_scores', 'track_scores value');
var actual = query.render(vs);
var expected = require('../fixtures/fallbackQuery_address_with_postcode.json');
var expected = {
query: {
bool: {
should: [
{ 'score field': 'score value'}
]
}
},
size: { $: 'size value' },
track_scores: { $: 'track_scores value' }
};
t.deepEquals(actual, expected);

@@ -218,34 +110,5 @@ t.end();

test('score with non-must or -should operator specified should be added as \'should\'', function(t) {
var score_view = function(vs) {
console.assert(vs !== null);
return { 'score field': 'score value' };
};
};
var query = new FallbackQuery();
query.score(score_view, 'non must or should value');
var vs = new VariableStore();
vs.var('size', 'size value');
vs.var('track_scores', 'track_scores value');
var actual = query.render(vs);
var expected = {
query: {
bool: {
should: [
{ 'score field': 'score value'}
]
}
},
size: { $: 'size value' },
track_scores: { $: 'track_scores value' }
};
t.deepEquals(actual, expected);
t.end();
});
module.exports.tests.scores = function(test, common) {
test('scores rendering to falsy values should not be added', function(t) {

@@ -258,3 +121,8 @@ var score_views_called = 0;

{ 'score field 1': 'score value 1' },
false, '', 0, null, undefined, NaN,
false,
'',
0,
null,
undefined,
NaN,
{ 'score field 2': 'score value 2' },

@@ -276,17 +144,10 @@ ].forEach(function(value) {

var actual = query.render(vs);
var actual_scoring_functions = actual.query.function_score.functions;
var expected = {
query: {
bool: {
should: [
{ 'score field 1': 'score value 1'},
{ 'score field 2': 'score value 2'}
]
}
},
size: { $: 'size value' },
track_scores: { $: 'track_scores value' }
};
var expected_scoring_functions = [
{ 'score field 1': 'score value 1'},
{ 'score field 2': 'score value 2'}
];
t.deepEquals(actual, expected);
t.deepEquals(actual_scoring_functions, expected_scoring_functions);
t.equals(score_views_called, 8);

@@ -333,3 +194,3 @@ t.end();

t.equals(filter_views_called, 8);
t.deepEquals(actual.query.bool.filter, expected_filter);
t.deepEquals(actual.query.function_score.query.filtered.filter.bool.must, expected_filter);
t.end();

@@ -342,3 +203,3 @@

function test(name, testFunction) {
return tape('address ' + name, testFunction);
return tape('FallbackQuery ' + name, testFunction);
}

@@ -345,0 +206,0 @@ for( var testCase in module.exports.tests ){

@@ -23,22 +23,22 @@ var GeodisambiguationQuery = require('../../layout/GeodisambiguationQuery');

t.equals(actual.query.bool.should.length, 10);
t.deepEquals(actual.query.bool.should[0], individualLayer('neighbourhood',
t.equals(actual.query.function_score.query.filtered.query.bool.should.length, 10);
t.deepEquals(actual.query.function_score.query.filtered.query.bool.should[0], individualLayer('neighbourhood',
'coarse neighbourhood value', ['parent.neighbourhood', 'parent.neighbourhood_a']));
t.deepEquals(actual.query.bool.should[1], individualLayer('borough',
t.deepEquals(actual.query.function_score.query.filtered.query.bool.should[1], individualLayer('borough',
'coarse neighbourhood value', ['parent.borough', 'parent.borough_a']));
t.deepEquals(actual.query.bool.should[2], individualLayer('locality',
t.deepEquals(actual.query.function_score.query.filtered.query.bool.should[2], individualLayer('locality',
'coarse neighbourhood value', ['parent.locality', 'parent.locality_a']));
t.deepEquals(actual.query.bool.should[3], individualLayer('localadmin',
t.deepEquals(actual.query.function_score.query.filtered.query.bool.should[3], individualLayer('localadmin',
'coarse neighbourhood value', ['parent.localadmin', 'parent.localadmin_a']));
t.deepEquals(actual.query.bool.should[4], individualLayer('county',
t.deepEquals(actual.query.function_score.query.filtered.query.bool.should[4], individualLayer('county',
'coarse neighbourhood value', ['parent.county', 'parent.county_a']));
t.deepEquals(actual.query.bool.should[5], individualLayer('macrocounty',
t.deepEquals(actual.query.function_score.query.filtered.query.bool.should[5], individualLayer('macrocounty',
'coarse neighbourhood value', ['parent.macrocounty', 'parent.macrocounty_a']));
t.deepEquals(actual.query.bool.should[6], individualLayer('region',
t.deepEquals(actual.query.function_score.query.filtered.query.bool.should[6], individualLayer('region',
'coarse neighbourhood value', ['parent.region', 'parent.region_a']));
t.deepEquals(actual.query.bool.should[7], individualLayer('macroregion',
t.deepEquals(actual.query.function_score.query.filtered.query.bool.should[7], individualLayer('macroregion',
'coarse neighbourhood value', ['parent.macroregion', 'parent.macroregion_a']));
t.deepEquals(actual.query.bool.should[8], individualLayer('dependency',
t.deepEquals(actual.query.function_score.query.filtered.query.bool.should[8], individualLayer('dependency',
'coarse neighbourhood value', ['parent.dependency', 'parent.dependency_a']));
t.deepEquals(actual.query.bool.should[9], individualLayer('country',
t.deepEquals(actual.query.function_score.query.filtered.query.bool.should[9], individualLayer('country',
'coarse neighbourhood value', ['parent.country', 'parent.country_a']));

@@ -67,22 +67,22 @@

t.equals(actual.query.bool.should.length, 10);
t.deepEquals(actual.query.bool.should[0], individualLayer('neighbourhood',
t.equals(actual.query.function_score.query.filtered.query.bool.should.length, 10);
t.deepEquals(actual.query.function_score.query.filtered.query.bool.should[0], individualLayer('neighbourhood',
'coarse borough value', ['parent.neighbourhood', 'parent.neighbourhood_a']));
t.deepEquals(actual.query.bool.should[1], individualLayer('borough',
t.deepEquals(actual.query.function_score.query.filtered.query.bool.should[1], individualLayer('borough',
'coarse borough value', ['parent.borough', 'parent.borough_a']));
t.deepEquals(actual.query.bool.should[2], individualLayer('locality',
t.deepEquals(actual.query.function_score.query.filtered.query.bool.should[2], individualLayer('locality',
'coarse borough value', ['parent.locality', 'parent.locality_a']));
t.deepEquals(actual.query.bool.should[3], individualLayer('localadmin',
t.deepEquals(actual.query.function_score.query.filtered.query.bool.should[3], individualLayer('localadmin',
'coarse borough value', ['parent.localadmin', 'parent.localadmin_a']));
t.deepEquals(actual.query.bool.should[4], individualLayer('county',
t.deepEquals(actual.query.function_score.query.filtered.query.bool.should[4], individualLayer('county',
'coarse borough value', ['parent.county', 'parent.county_a']));
t.deepEquals(actual.query.bool.should[5], individualLayer('macrocounty',
t.deepEquals(actual.query.function_score.query.filtered.query.bool.should[5], individualLayer('macrocounty',
'coarse borough value', ['parent.macrocounty', 'parent.macrocounty_a']));
t.deepEquals(actual.query.bool.should[6], individualLayer('region',
t.deepEquals(actual.query.function_score.query.filtered.query.bool.should[6], individualLayer('region',
'coarse borough value', ['parent.region', 'parent.region_a']));
t.deepEquals(actual.query.bool.should[7], individualLayer('macroregion',
t.deepEquals(actual.query.function_score.query.filtered.query.bool.should[7], individualLayer('macroregion',
'coarse borough value', ['parent.macroregion', 'parent.macroregion_a']));
t.deepEquals(actual.query.bool.should[8], individualLayer('dependency',
t.deepEquals(actual.query.function_score.query.filtered.query.bool.should[8], individualLayer('dependency',
'coarse borough value', ['parent.dependency', 'parent.dependency_a']));
t.deepEquals(actual.query.bool.should[9], individualLayer('country',
t.deepEquals(actual.query.function_score.query.filtered.query.bool.should[9], individualLayer('country',
'coarse borough value', ['parent.country', 'parent.country_a']));

@@ -110,22 +110,22 @@

t.equals(actual.query.bool.should.length, 10);
t.deepEquals(actual.query.bool.should[0], individualLayer('neighbourhood',
t.equals(actual.query.function_score.query.filtered.query.bool.should.length, 10);
t.deepEquals(actual.query.function_score.query.filtered.query.bool.should[0], individualLayer('neighbourhood',
'coarse city value', ['parent.neighbourhood', 'parent.neighbourhood_a']));
t.deepEquals(actual.query.bool.should[1], individualLayer('borough',
t.deepEquals(actual.query.function_score.query.filtered.query.bool.should[1], individualLayer('borough',
'coarse city value', ['parent.borough', 'parent.borough_a']));
t.deepEquals(actual.query.bool.should[2], individualLayer('locality',
t.deepEquals(actual.query.function_score.query.filtered.query.bool.should[2], individualLayer('locality',
'coarse city value', ['parent.locality', 'parent.locality_a']));
t.deepEquals(actual.query.bool.should[3], individualLayer('localadmin',
t.deepEquals(actual.query.function_score.query.filtered.query.bool.should[3], individualLayer('localadmin',
'coarse city value', ['parent.localadmin', 'parent.localadmin_a']));
t.deepEquals(actual.query.bool.should[4], individualLayer('county',
t.deepEquals(actual.query.function_score.query.filtered.query.bool.should[4], individualLayer('county',
'coarse city value', ['parent.county', 'parent.county_a']));
t.deepEquals(actual.query.bool.should[5], individualLayer('macrocounty',
t.deepEquals(actual.query.function_score.query.filtered.query.bool.should[5], individualLayer('macrocounty',
'coarse city value', ['parent.macrocounty', 'parent.macrocounty_a']));
t.deepEquals(actual.query.bool.should[6], individualLayer('region',
t.deepEquals(actual.query.function_score.query.filtered.query.bool.should[6], individualLayer('region',
'coarse city value', ['parent.region', 'parent.region_a']));
t.deepEquals(actual.query.bool.should[7], individualLayer('macroregion',
t.deepEquals(actual.query.function_score.query.filtered.query.bool.should[7], individualLayer('macroregion',
'coarse city value', ['parent.macroregion', 'parent.macroregion_a']));
t.deepEquals(actual.query.bool.should[8], individualLayer('dependency',
t.deepEquals(actual.query.function_score.query.filtered.query.bool.should[8], individualLayer('dependency',
'coarse city value', ['parent.dependency', 'parent.dependency_a']));
t.deepEquals(actual.query.bool.should[9], individualLayer('country',
t.deepEquals(actual.query.function_score.query.filtered.query.bool.should[9], individualLayer('country',
'coarse city value', ['parent.country', 'parent.country_a']));

@@ -152,22 +152,22 @@

t.equals(actual.query.bool.should.length, 10);
t.deepEquals(actual.query.bool.should[0], individualLayer('neighbourhood',
t.equals(actual.query.function_score.query.filtered.query.bool.should.length, 10);
t.deepEquals(actual.query.function_score.query.filtered.query.bool.should[0], individualLayer('neighbourhood',
'coarse county value', ['parent.neighbourhood', 'parent.neighbourhood_a']));
t.deepEquals(actual.query.bool.should[1], individualLayer('borough',
t.deepEquals(actual.query.function_score.query.filtered.query.bool.should[1], individualLayer('borough',
'coarse county value', ['parent.borough', 'parent.borough_a']));
t.deepEquals(actual.query.bool.should[2], individualLayer('locality',
t.deepEquals(actual.query.function_score.query.filtered.query.bool.should[2], individualLayer('locality',
'coarse county value', ['parent.locality', 'parent.locality_a']));
t.deepEquals(actual.query.bool.should[3], individualLayer('localadmin',
t.deepEquals(actual.query.function_score.query.filtered.query.bool.should[3], individualLayer('localadmin',
'coarse county value', ['parent.localadmin', 'parent.localadmin_a']));
t.deepEquals(actual.query.bool.should[4], individualLayer('county',
t.deepEquals(actual.query.function_score.query.filtered.query.bool.should[4], individualLayer('county',
'coarse county value', ['parent.county', 'parent.county_a']));
t.deepEquals(actual.query.bool.should[5], individualLayer('macrocounty',
t.deepEquals(actual.query.function_score.query.filtered.query.bool.should[5], individualLayer('macrocounty',
'coarse county value', ['parent.macrocounty', 'parent.macrocounty_a']));
t.deepEquals(actual.query.bool.should[6], individualLayer('region',
t.deepEquals(actual.query.function_score.query.filtered.query.bool.should[6], individualLayer('region',
'coarse county value', ['parent.region', 'parent.region_a']));
t.deepEquals(actual.query.bool.should[7], individualLayer('macroregion',
t.deepEquals(actual.query.function_score.query.filtered.query.bool.should[7], individualLayer('macroregion',
'coarse county value', ['parent.macroregion', 'parent.macroregion_a']));
t.deepEquals(actual.query.bool.should[8], individualLayer('dependency',
t.deepEquals(actual.query.function_score.query.filtered.query.bool.should[8], individualLayer('dependency',
'coarse county value', ['parent.dependency', 'parent.dependency_a']));
t.deepEquals(actual.query.bool.should[9], individualLayer('country',
t.deepEquals(actual.query.function_score.query.filtered.query.bool.should[9], individualLayer('country',
'coarse county value', ['parent.country', 'parent.country_a']));

@@ -193,22 +193,22 @@

t.equals(actual.query.bool.should.length, 10);
t.deepEquals(actual.query.bool.should[0], individualLayer('neighbourhood',
t.equals(actual.query.function_score.query.filtered.query.bool.should.length, 10);
t.deepEquals(actual.query.function_score.query.filtered.query.bool.should[0], individualLayer('neighbourhood',
'coarse region value', ['parent.neighbourhood', 'parent.neighbourhood_a']));
t.deepEquals(actual.query.bool.should[1], individualLayer('borough',
t.deepEquals(actual.query.function_score.query.filtered.query.bool.should[1], individualLayer('borough',
'coarse region value', ['parent.borough', 'parent.borough_a']));
t.deepEquals(actual.query.bool.should[2], individualLayer('locality',
t.deepEquals(actual.query.function_score.query.filtered.query.bool.should[2], individualLayer('locality',
'coarse region value', ['parent.locality', 'parent.locality_a']));
t.deepEquals(actual.query.bool.should[3], individualLayer('localadmin',
t.deepEquals(actual.query.function_score.query.filtered.query.bool.should[3], individualLayer('localadmin',
'coarse region value', ['parent.localadmin', 'parent.localadmin_a']));
t.deepEquals(actual.query.bool.should[4], individualLayer('county',
t.deepEquals(actual.query.function_score.query.filtered.query.bool.should[4], individualLayer('county',
'coarse region value', ['parent.county', 'parent.county_a']));
t.deepEquals(actual.query.bool.should[5], individualLayer('macrocounty',
t.deepEquals(actual.query.function_score.query.filtered.query.bool.should[5], individualLayer('macrocounty',
'coarse region value', ['parent.macrocounty', 'parent.macrocounty_a']));
t.deepEquals(actual.query.bool.should[6], individualLayer('region',
t.deepEquals(actual.query.function_score.query.filtered.query.bool.should[6], individualLayer('region',
'coarse region value', ['parent.region', 'parent.region_a']));
t.deepEquals(actual.query.bool.should[7], individualLayer('macroregion',
t.deepEquals(actual.query.function_score.query.filtered.query.bool.should[7], individualLayer('macroregion',
'coarse region value', ['parent.macroregion', 'parent.macroregion_a']));
t.deepEquals(actual.query.bool.should[8], individualLayer('dependency',
t.deepEquals(actual.query.function_score.query.filtered.query.bool.should[8], individualLayer('dependency',
'coarse region value', ['parent.dependency', 'parent.dependency_a']));
t.deepEquals(actual.query.bool.should[9], individualLayer('country',
t.deepEquals(actual.query.function_score.query.filtered.query.bool.should[9], individualLayer('country',
'coarse region value', ['parent.country', 'parent.country_a']));

@@ -233,22 +233,22 @@

t.equals(actual.query.bool.should.length, 10);
t.deepEquals(actual.query.bool.should[0], individualLayer('neighbourhood',
t.equals(actual.query.function_score.query.filtered.query.bool.should.length, 10);
t.deepEquals(actual.query.function_score.query.filtered.query.bool.should[0], individualLayer('neighbourhood',
'coarse country value', ['parent.neighbourhood', 'parent.neighbourhood_a']));
t.deepEquals(actual.query.bool.should[1], individualLayer('borough',
t.deepEquals(actual.query.function_score.query.filtered.query.bool.should[1], individualLayer('borough',
'coarse country value', ['parent.borough', 'parent.borough_a']));
t.deepEquals(actual.query.bool.should[2], individualLayer('locality',
t.deepEquals(actual.query.function_score.query.filtered.query.bool.should[2], individualLayer('locality',
'coarse country value', ['parent.locality', 'parent.locality_a']));
t.deepEquals(actual.query.bool.should[3], individualLayer('localadmin',
t.deepEquals(actual.query.function_score.query.filtered.query.bool.should[3], individualLayer('localadmin',
'coarse country value', ['parent.localadmin', 'parent.localadmin_a']));
t.deepEquals(actual.query.bool.should[4], individualLayer('county',
t.deepEquals(actual.query.function_score.query.filtered.query.bool.should[4], individualLayer('county',
'coarse country value', ['parent.county', 'parent.county_a']));
t.deepEquals(actual.query.bool.should[5], individualLayer('macrocounty',
t.deepEquals(actual.query.function_score.query.filtered.query.bool.should[5], individualLayer('macrocounty',
'coarse country value', ['parent.macrocounty', 'parent.macrocounty_a']));
t.deepEquals(actual.query.bool.should[6], individualLayer('region',
t.deepEquals(actual.query.function_score.query.filtered.query.bool.should[6], individualLayer('region',
'coarse country value', ['parent.region', 'parent.region_a']));
t.deepEquals(actual.query.bool.should[7], individualLayer('macroregion',
t.deepEquals(actual.query.function_score.query.filtered.query.bool.should[7], individualLayer('macroregion',
'coarse country value', ['parent.macroregion', 'parent.macroregion_a']));
t.deepEquals(actual.query.bool.should[8], individualLayer('dependency',
t.deepEquals(actual.query.function_score.query.filtered.query.bool.should[8], individualLayer('dependency',
'coarse country value', ['parent.dependency', 'parent.dependency_a']));
t.deepEquals(actual.query.bool.should[9], individualLayer('country',
t.deepEquals(actual.query.function_score.query.filtered.query.bool.should[9], individualLayer('country',
'coarse country value', ['parent.country', 'parent.country_a']));

@@ -288,104 +288,2 @@

module.exports.tests.scores = function(test, common) {
test('score with operator specified should be honored and in order', function(t) {
var score_view1 = function(vs) {
console.assert(vs !== null);
return { 'score field 1': 'score value 1' };
};
var score_view2 = function(vs) {
console.assert(vs !== null);
return { 'score field 2': 'score value 2' };
};
var score_view3 = function(vs) {
console.assert(vs !== null);
return { 'score field 3': 'score value 3' };
};
var score_view4 = function(vs) {
console.assert(vs !== null);
return { 'score field 4': 'score value 4' };
};
var query = new GeodisambiguationQuery();
query.score(score_view1, 'must');
query.score(score_view2, 'should');
query.score(score_view3, 'must');
query.score(score_view4, 'should');
var vs = new VariableStore();
vs.var('size', 'size value');
vs.var('track_scores', 'track_scores value');
var actual = query.render(vs);
var actual_shoulds = actual.query.bool.should;
var actual_musts = actual.query.bool.must;
var expected_shoulds = [
{ 'score field 2': 'score value 2'},
{ 'score field 4': 'score value 4'}
];
var expected_musts = [
{ 'score field 1': 'score value 1'},
{ 'score field 3': 'score value 3'}
];
t.deepEquals(actual_shoulds.slice(actual_shoulds.length-2), expected_shoulds);
t.deepEquals(actual_musts.slice(actual_musts.length-2), expected_musts);
t.end();
});
test('score without operator specified should be added as \'should\'', function(t) {
var score_view = function(vs) {
console.assert(vs !== null);
return { 'score field': 'score value' };
};
var query = new GeodisambiguationQuery();
query.score(score_view);
var vs = new VariableStore();
vs.var('size', 'size value');
vs.var('track_scores', 'track_scores value');
var actual = query.render(vs);
var actual_shoulds = actual.query.bool.should;
var expected_shoulds = [
{ 'score field': 'score value'}
];
t.deepEquals(actual_shoulds.slice(actual_shoulds.length-1), expected_shoulds);
t.end();
});
test('score with non-must or -should operator specified should be added as \'should\'', function(t) {
var score_view = function(vs) {
console.assert(vs !== null);
return { 'score field': 'score value' };
};
var query = new GeodisambiguationQuery();
query.score(score_view, 'non must or should value');
var vs = new VariableStore();
vs.var('size', 'size value');
vs.var('track_scores', 'track_scores value');
var actual = query.render(vs);
var actual_shoulds = actual.query.bool.should;
var expected_shoulds = [
{ 'score field': 'score value'}
];
t.deepEquals(actual_shoulds.slice(actual_shoulds.length-1), expected_shoulds);
t.end();
});
test('scores rendering to falsy values should not be added', function(t) {

@@ -398,3 +296,8 @@ var score_views_called = 0;

{ 'score field 1': 'score value 1' },
false, '', 0, null, undefined, NaN,
false,
'',
0,
null,
undefined,
NaN,
{ 'score field 2': 'score value 2' },

@@ -416,5 +319,5 @@ ].forEach(function(value) {

var actual = query.render(vs);
var actual_shoulds = actual.query.bool.should;
var actual_scoring_functions = actual.query.function_score.functions;
var expected_shoulds = [
var expected_scoring_functions = [
{ 'score field 1': 'score value 1'},

@@ -424,3 +327,3 @@ { 'score field 2': 'score value 2'}

t.deepEquals(actual_shoulds.slice(actual_shoulds.length-2), expected_shoulds);
t.deepEquals(actual_scoring_functions, expected_scoring_functions);
t.equals(score_views_called, 8);

@@ -467,3 +370,3 @@ t.end();

t.equals(filter_views_called, 8);
t.deepEquals(actual.query.bool.filter, expected_filter);
t.deepEquals(actual.query.function_score.query.filtered.filter.bool.must, expected_filter);
t.end();

@@ -470,0 +373,0 @@

@@ -18,2 +18,3 @@

require('./view/focus.js'),
require('./view/focus_only_function.js'),
require('./view/layers.js'),

@@ -25,3 +26,5 @@ require('./view/localregions.js'),

require('./view/popularity.js'),
require('./view/popularity_only_function.js'),
require('./view/population.js'),
require('./view/population_only_function.js'),
require('./view/sort_distance.js'),

@@ -28,0 +31,0 @@ require('./view/sort_numeric_script.js'),

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc