ckanext-spatial
ckanext-spatial copied to clipboard
solr-spatial-field search backend errors when searching across the anti-meridian
Context
Tested using CKAN 2.7.4 and solr 6.5 with the JTS 1.14 plugin and the solr-spatial-field configured in the schema.xml.
Issue
When using the solr-spatial-field search backend, and querying across the anti-meridian I.E https://demo.ckan.org/dataset?ext_bbox=177,-38,184,-37 then the query generated for solr will return a 400 http response.
The problem is that the ENVELOPE
part of the query has a maxx
value that is greater than 180. when solr expects the value to be between -180 and 180.
Solution
In the _params_for_solr_spatial_field_search
method, we could move the value into the expected bounds.
def _params_for_solr_spatial_field_search(self, bbox, search_params):
'''
This will add an fq filter with the form:
+spatial_geom:"Intersects(ENVELOPE({minx}, {miny}, {maxx}, {maxy}))
'''
if bbox['maxx'] > 180:
bbox['maxx'] = -180 + (bbox['maxx'] - 180)
search_params['fq_list'] = search_params.get('fq_list', [])
search_params['fq_list'].append('+spatial_geom:"Intersects(ENVELOPE({minx}, {maxx}, {maxy}, {miny}))"'
.format(minx=bbox['minx'], miny=bbox['miny'], maxx=bbox['maxx'], maxy=bbox['maxy']))