From 2c8ce9b652cb5384ab421ec1a060e9f5e40da2db Mon Sep 17 00:00:00 2001 From: Tobias Kohr Date: Fri, 13 Jan 2023 14:09:40 +0100 Subject: [PATCH] feat(elasticsearch): boost results with intersecting geom and include results without intersecting geom instead of excluding them --- .../elasticsearch.service.spec.ts | 22 ++++++------- .../elasticsearch/elasticsearch.service.ts | 31 ++++++++++--------- 2 files changed, 28 insertions(+), 25 deletions(-) diff --git a/libs/util/shared/src/lib/elasticsearch/elasticsearch.service.spec.ts b/libs/util/shared/src/lib/elasticsearch/elasticsearch.service.spec.ts index 1d0d9db61c..46d111c0d7 100644 --- a/libs/util/shared/src/lib/elasticsearch/elasticsearch.service.spec.ts +++ b/libs/util/shared/src/lib/elasticsearch/elasticsearch.service.spec.ts @@ -211,7 +211,7 @@ describe('ElasticsearchService', () => { type: 'Polygon', } }) - it('adds a criteria for intersecting with it and boosting on geoms within', () => { + it('adds boosting of 7 for intersecting with it and boosting of 10 on geoms within', () => { const query = service['buildPayloadQuery']( { Org: { @@ -225,16 +225,7 @@ describe('ElasticsearchService', () => { ) expect(query).toEqual({ bool: { - filter: [ - { - geo_shape: { - geom: { - shape: geojsonPolygon, - relation: 'intersects', - }, - }, - }, - ], + filter: [], must: [ { terms: { @@ -281,6 +272,15 @@ describe('ElasticsearchService', () => { boost: 10.0, }, }, + { + geo_shape: { + geom: { + shape: geojsonPolygon, + relation: 'intersects', + }, + boost: 7.0, + }, + }, ], }, }) diff --git a/libs/util/shared/src/lib/elasticsearch/elasticsearch.service.ts b/libs/util/shared/src/lib/elasticsearch/elasticsearch.service.ts index 0b96a863bd..808f38b8b0 100644 --- a/libs/util/shared/src/lib/elasticsearch/elasticsearch.service.ts +++ b/libs/util/shared/src/lib/elasticsearch/elasticsearch.service.ts @@ -165,23 +165,26 @@ export class ElasticsearchService { }) } if (geometry) { - should.push({ - geo_shape: { - geom: { - shape: geometry, - relation: 'within', + should.push( + { + geo_shape: { + geom: { + shape: geometry, + relation: 'within', + }, + boost: 10.0, }, - boost: 10.0, }, - }) - filter.push({ - geo_shape: { - geom: { - shape: geometry, - relation: 'intersects', + { + geo_shape: { + geom: { + shape: geometry, + relation: 'intersects', + }, + boost: 7.0, }, - }, - }) + } + ) } return {