Skip to content

Commit

Permalink
Update geo shape filter queries to use bounding box logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron Caldwell committed Mar 2, 2021
1 parent 31889a5 commit 7d4495f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ export interface ESPolygonFilter {

export function createExtentFilter(
mapExtent: MapExtent,
geoFieldName: string,
geoFieldType: ES_GEO_FIELD_TYPE
geoFieldName: string
): ESPolygonFilter | ESGeoBoundingBoxFilter;

export function makeESBbox({ maxLat, maxLon, minLat, minLon }: MapExtent): ESBBox;
Original file line number Diff line number Diff line change
Expand Up @@ -280,33 +280,16 @@ export function makeESBbox({ maxLat, maxLon, minLat, minLon }) {
return esBbox;
}

function createGeoBoundBoxFilter({ maxLat, maxLon, minLat, minLon }, geoFieldName) {
const boundingBox = makeESBbox({ maxLat, maxLon, minLat, minLon });
return {
geo_bounding_box: {
[geoFieldName]: boundingBox,
},
};
}

export function createExtentFilter(mapExtent, geoFieldName, geoFieldType) {
ensureGeoField(geoFieldType);

export function createExtentFilter(mapExtent, geoFieldName) {
// Extent filters are used to dynamically filter data for the current map view port.
// Continue to use geo_bounding_box queries for extent filters
// 1) geo_bounding_box queries are faster than polygon queries
// 2) geo_shape benefits of pre-indexed shapes and
// compatability across multi-indices with geo_point and geo_shape do not apply to this use case.
if (geoFieldType === ES_GEO_FIELD_TYPE.GEO_POINT) {
return createGeoBoundBoxFilter(mapExtent, geoFieldName);
}

// compatibility across multi-indices with geo_point and geo_shape do not apply to this use case.
const boundingBox = makeESBbox(mapExtent);
return {
geo_shape: {
[geoFieldName]: {
shape: formatEnvelopeAsPolygon(mapExtent),
relation: ES_SPATIAL_RELATIONS.INTERSECTS,
},
geo_bounding_box: {
[geoFieldName]: boundingBox,
},
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,11 +236,7 @@ export class AbstractESSource extends AbstractVectorSource implements IESSource
typeof searchFilters.geogridPrecision === 'number'
? expandToTileBoundaries(searchFilters.buffer, searchFilters.geogridPrecision)
: searchFilters.buffer;
const extentFilter = createExtentFilter(
buffer,
geoField.name,
geoField.type as ES_GEO_FIELD_TYPE
);
const extentFilter = createExtentFilter(buffer, geoField.name);

// @ts-expect-error
allFilters.push(extentFilter);
Expand Down

0 comments on commit 7d4495f

Please sign in to comment.