Skip to content

Commit

Permalink
feat(elasticsearch): boost results with intersecting geom
Browse files Browse the repository at this point in the history
and include results without intersecting geom instead of excluding them
  • Loading branch information
tkohr committed Jan 13, 2023
1 parent 885fc96 commit 2c8ce9b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -225,16 +225,7 @@ describe('ElasticsearchService', () => {
)
expect(query).toEqual({
bool: {
filter: [
{
geo_shape: {
geom: {
shape: geojsonPolygon,
relation: 'intersects',
},
},
},
],
filter: [],
must: [
{
terms: {
Expand Down Expand Up @@ -281,6 +272,15 @@ describe('ElasticsearchService', () => {
boost: 10.0,
},
},
{
geo_shape: {
geom: {
shape: geojsonPolygon,
relation: 'intersects',
},
boost: 7.0,
},
},
],
},
})
Expand Down
31 changes: 17 additions & 14 deletions libs/util/shared/src/lib/elasticsearch/elasticsearch.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 2c8ce9b

Please sign in to comment.