Skip to content

Commit

Permalink
Merge pull request #111 from pelias/use-match-leaf-function
Browse files Browse the repository at this point in the history
feat(match_phrase): Use match_phrase lib
  • Loading branch information
orangejulius authored Oct 3, 2019
2 parents f311c4c + ab79804 commit 4d0298f
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 164 deletions.
75 changes: 10 additions & 65 deletions layout/AddressesUsingIdsQuery.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,14 @@
'use strict';

const _ = require('lodash');
const Query = require('./Query');
const match_phrase = require('../lib/leaf/match_phrase');

function createAddressShould(vs) {
const should = {
bool: {
_name: 'fallback.address',
must: [
{
match_phrase: {
'address_parts.number': {
query: vs.var('input:housenumber')
}
}
},
{
match_phrase: {
'address_parts.street': {
query: vs.var('input:street')
}
}
}
match_phrase('address_parts.number', vs.var('input:housenumber')),
match_phrase('address_parts.street', vs.var('input:street'))
],
filter: {
term: {
Expand All @@ -43,27 +30,9 @@ function createUnitAndAddressShould(vs) {
bool: {
_name: 'fallback.address',
must: [
{
match_phrase: {
'address_parts.unit': {
query: vs.var('input:unit')
}
}
},
{
match_phrase: {
'address_parts.number': {
query: vs.var('input:housenumber')
}
}
},
{
match_phrase: {
'address_parts.street': {
query: vs.var('input:street')
}
}
}
match_phrase('address_parts.unit', vs.var('input:unit')),
match_phrase('address_parts.number', vs.var('input:housenumber')),
match_phrase('address_parts.street', vs.var('input:street'))
],
filter: {
term: {
Expand All @@ -85,27 +54,9 @@ function createPostcodeAndAddressShould(vs) {
bool: {
_name: 'fallback.address',
must: [
{
match_phrase: {
'address_parts.zip': {
query: vs.var('input:postcode')
}
}
},
{
match_phrase: {
'address_parts.number': {
query: vs.var('input:housenumber')
}
}
},
{
match_phrase: {
'address_parts.street': {
query: vs.var('input:street')
}
}
}
match_phrase('address_parts.zip', vs.var('input:postcode')),
match_phrase('address_parts.number', vs.var('input:housenumber')),
match_phrase('address_parts.street', vs.var('input:street'))
],
filter: {
term: {
Expand All @@ -127,13 +78,7 @@ function createStreetShould(vs) {
bool: {
_name: 'fallback.street',
must: [
{
match_phrase: {
'address_parts.street': {
query: vs.var('input:street')
}
}
}
match_phrase('address_parts.street', vs.var('input:street'))
],
filter: {
term: {
Expand Down
61 changes: 11 additions & 50 deletions layout/FallbackQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
var _ = require('lodash');
var baseQuery = require('./baseQuery');

const match_phrase = require('../lib/leaf/match_phrase');

function Layout(){
this._score = [];
this._filter = [];
Expand Down Expand Up @@ -110,13 +112,9 @@ function addSecondary(value, fields) {
function addSecPostCode(vs, o) {
// add postcode if specified
if (vs.isset('input:postcode')) {
o.bool.should.push({
match_phrase: {
'address_parts.zip': {
query: vs.var('input:postcode').toString()
}
}
});
o.bool.should.push(
match_phrase('address_parts.zip', vs.var('input:postcode'))
);
}
}

Expand Down Expand Up @@ -233,27 +231,9 @@ function addUnitAndHouseNumberAndStreet(vs) {
bool: {
_name: 'fallback.address',
must: [
{
match_phrase: {
'address_parts.unit': {
query: vs.var('input:unit').toString()
}
}
},
{
match_phrase: {
'address_parts.number': {
query: vs.var('input:housenumber').toString()
}
}
},
{
match_phrase: {
'address_parts.street': {
query: vs.var('input:street').toString()
}
}
}
match_phrase('address_parts.unit', vs.var('input:unit')),
match_phrase('address_parts.number', vs.var('input:housenumber')),
match_phrase('address_parts.street', vs.var('input:street'))
],
should: [],
filter: {
Expand All @@ -277,28 +257,15 @@ function addUnitAndHouseNumberAndStreet(vs) {
addSecCountry(vs, o);

return o;

}

function addHouseNumberAndStreet(vs) {
var o = {
bool: {
_name: 'fallback.address',
must: [
{
match_phrase: {
'address_parts.number': {
query: vs.var('input:housenumber').toString()
}
}
},
{
match_phrase: {
'address_parts.street': {
query: vs.var('input:street').toString()
}
}
}
match_phrase('address_parts.number', vs.var('input:housenumber')),
match_phrase('address_parts.street', vs.var('input:street'))
],
should: [],
filter: {
Expand Down Expand Up @@ -330,13 +297,7 @@ function addStreet(vs) {
bool: {
_name: 'fallback.street',
must: [
{
match_phrase: {
'address_parts.street': {
query: vs.var('input:street').toString()
}
}
}
match_phrase('address_parts.street', vs.var('input:street'))
],
should: [],
filter: {
Expand Down
60 changes: 11 additions & 49 deletions layout/StructuredFallbackQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
var _ = require('lodash');
var baseQuery = require('./baseQuery');

const match_phrase = require('../lib/leaf/match_phrase');

function Layout(){
this._score = [];
this._filter = [];
Expand Down Expand Up @@ -68,13 +70,9 @@ function addSecondary(value, fields) {
function addSecPostCode(vs, o) {
// add postcode if specified
if (vs.isset('input:postcode')) {
o.bool.should.push({
match_phrase: {
'address_parts.zip': {
query: vs.var('input:postcode').toString()
}
}
});
o.bool.should.push(
match_phrase('address_parts.zip', vs.var('input:postcode'))
);
}
}

Expand Down Expand Up @@ -192,27 +190,9 @@ function addUnitAndHouseNumberAndStreet(vs) {
bool: {
_name: 'fallback.address',
must: [
{
match_phrase: {
'address_parts.unit': {
query: vs.var('input:unit').toString()
}
}
},
{
match_phrase: {
'address_parts.number': {
query: vs.var('input:housenumber').toString()
}
}
},
{
match_phrase: {
'address_parts.street': {
query: vs.var('input:street').toString()
}
}
}
match_phrase('address_parts.unit', vs.var('input:unit')),
match_phrase('address_parts.number', vs.var('input:housenumber')),
match_phrase('address_parts.street', vs.var('input:street'))
],
should: [],
filter: {
Expand Down Expand Up @@ -281,20 +261,8 @@ function addHouseNumberAndStreet(vs) {
bool: {
_name: 'fallback.address',
must: [
{
match_phrase: {
'address_parts.number': {
query: vs.var('input:housenumber').toString()
}
}
},
{
match_phrase: {
'address_parts.street': {
query: vs.var('input:street').toString()
}
}
}
match_phrase('address_parts.number', vs.var('input:housenumber')),
match_phrase('address_parts.street', vs.var('input:street'))
],
should: [],
filter: {
Expand Down Expand Up @@ -326,13 +294,7 @@ function addStreet(vs) {
bool: {
_name: 'fallback.street',
must: [
{
match_phrase: {
'address_parts.street': {
query: vs.var('input:street').toString()
}
}
}
match_phrase('address_parts.street', vs.var('input:street'))
],
should: [],
filter: {
Expand Down

0 comments on commit 4d0298f

Please sign in to comment.