From a0cb9ec55cd3d8f3c10e7104e01db6e62ed43649 Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Tue, 1 Sep 2015 18:31:34 +0200 Subject: [PATCH] experimental commit to test soft focus --- query/search.js | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/query/search.js b/query/search.js index bb56197f..20078f5a 100644 --- a/query/search.js +++ b/query/search.js @@ -15,7 +15,7 @@ function generate( params ){ }; } - var query = queries.distance( centroid, { size: params.size } ); + var query = queries.distance( null, { size: params.size } ); var input = params.input; if (params.bbox) { @@ -63,6 +63,35 @@ function generate( params ){ } }); + // @experimental + // add soft focus + if( centroid ){ + query.query.filtered.query.bool.should.push({ + 'function_score': { + 'query': { + 'match': { + 'phrase.default': { + 'query': input, + 'analyzer': 'peliasPhrase', + 'type': 'phrase', + 'slop': 2 + } + } + }, + 'functions': [{ + 'linear': { + 'center_point': { + 'origin': centroid, + 'offset': '50km', + 'scale': '100km', + 'decay': 0.01 + } + } + }] + } + }); + } + query.sort = query.sort.concat( sort( params ) ); return query;