def before_search(self,search_params): if 'extras' in search_params and 'ext_bbox' in search_params['extras'] \ and search_params['extras']['ext_bbox']: bbox = validate_bbox(search_params['extras']['ext_bbox']) if not bbox: raise SearchError('Wrong bounding box provided') extents = bbox_query(bbox) if extents.count() == 0: # We don't need to perform the search search_params['abort_search'] = True else: # We'll perform the existing search but also filtering by the ids # of datasets within the bbox bbox_query_ids = [extent.package_id for extent in extents] q = search_params.get('q','') new_q = '%s AND ' % q if q else '' new_q += '(%s)' % ' OR '.join(['id:%s' % id for id in bbox_query_ids]) search_params['q'] = new_q return search_params
def before_search(self, search_params): if 'extras' in search_params and 'ext_bbox' in search_params['extras'] \ and search_params['extras']['ext_bbox']: bbox = validate_bbox(search_params['extras']['ext_bbox']) if not bbox: raise SearchError('Wrong bounding box provided') extents = bbox_query(bbox) if extents.count() == 0: # We don't need to perform the search search_params['abort_search'] = True else: # We'll perform the existing search but also filtering by the ids # of datasets within the bbox bbox_query_ids = [extent.package_id for extent in extents] q = search_params.get('q', '') new_q = '%s AND ' % q if q else '' new_q += '(%s)' % ' OR '.join( ['id:%s' % id for id in bbox_query_ids]) search_params['q'] = new_q return search_params
def test_query(self): ''' ''' bbox_dict = self.x_values_to_bbox((2, 7)) t0 = time.time() q = bbox_query(bbox_dict) t1 = time.time() print u'bbox_query took: ', t1 - t0
def test_query(self): ''' ''' bbox_dict = self.x_values_to_bbox((2, 5)) package_ids = [res.package_id for res in bbox_query(bbox_dict)] package_titles = [model.Package.get(id_).title for id_ in package_ids] assert_equal(set(package_titles), set( (u'(0, 3)', u'(0, 4)', u'(4, 5)')))
def _params_for_postgis_search(self, bbox, search_params): from ckanext.spatial.lib import bbox_query, bbox_query_ordered from ckan.lib.search import SearchError # Note: This will be deprecated at some point in favour of the # Solr 4 spatial sorting capabilities if search_params.get('sort') == 'spatial desc' and \ tk.asbool(config.get('ckanext.spatial.use_postgis_sorting', 'False')): if search_params['q'] or search_params['fq']: raise SearchError( 'Spatial ranking cannot be mixed with other search parameters' ) # ...because it is too inefficient to use SOLR to filter # results and return the entire set to this class and # after_search do the sorting and paging. extents = bbox_query_ordered(bbox) are_no_results = not extents search_params['extras']['ext_rows'] = search_params['rows'] search_params['extras']['ext_start'] = search_params['start'] # this SOLR query needs to return no actual results since # they are in the wrong order anyway. We just need this SOLR # query to get the count and facet counts. rows = 0 search_params['sort'] = None # SOLR should not sort. # Store the rankings of the results for this page, so for # after_search to construct the correctly sorted results rows = search_params['extras']['ext_rows'] = search_params['rows'] start = search_params['extras']['ext_start'] = search_params[ 'start'] search_params['extras']['ext_spatial'] = [ (extent.package_id, extent.spatial_ranking) \ for extent in extents[start:start+rows]] else: extents = bbox_query(bbox) are_no_results = extents.count() == 0 if are_no_results: # We don't need to perform the search search_params['abort_search'] = True else: # We'll perform the existing search but also filtering by the ids # of datasets within the bbox bbox_query_ids = [extent.package_id for extent in extents] q = search_params.get('q', '').strip() or '""' # Note: `"" AND` query doesn't work in github ci new_q = '%s AND ' % q if q and q != '""' else '' new_q += '(%s)' % ' OR '.join( ['id:%s' % id for id in bbox_query_ids]) search_params['q'] = new_q return search_params
def before_search(self,search_params): if 'extras' in search_params and 'ext_bbox' in search_params['extras'] \ and search_params['extras']['ext_bbox']: bbox = validate_bbox(search_params['extras']['ext_bbox']) if not bbox: raise SearchError('Wrong bounding box provided') if 'sort' in search_params and search_params['sort'] == 'spatial desc': if search_params['q'] or search_params['fq']: raise SearchError('Spatial ranking cannot be mixed with other search parameters') # ...because it is too inefficient to use SOLR to filter # results and return the entire set to this class and # after_search do the sorting and paging. extents = bbox_query_ordered(bbox) are_no_results = not extents search_params['extras']['ext_rows'] = search_params['rows'] search_params['extras']['ext_start'] = search_params['start'] # this SOLR query needs to return no actual results since # they are in the wrong order anyway. We just need this SOLR # query to get the count and facet counts. rows = 0 search_params['sort'] = None # SOLR should not sort. # Store the rankings of the results for this page, so for # after_search to construct the correctly sorted results rows = search_params['extras']['ext_rows'] = search_params['rows'] start = search_params['extras']['ext_start'] = search_params['start'] search_params['extras']['ext_spatial'] = [ (extent.package_id, extent.spatial_ranking) \ for extent in extents[start:start+rows]] else: extents = bbox_query(bbox) are_no_results = extents.count() == 0 if are_no_results: # We don't need to perform the search search_params['abort_search'] = True else: # We'll perform the existing search but also filtering by the ids # of datasets within the bbox bbox_query_ids = [extent.package_id for extent in extents] q = search_params.get('q','').strip() or '""' new_q = '%s AND ' % q if q else '' new_q += '(%s)' % ' OR '.join(['id:%s' % id for id in bbox_query_ids]) search_params['q'] = new_q return search_params
def _params_for_postgis_search(self, bbox, search_params): from ckanext.spatial.lib import bbox_query, bbox_query_ordered from ckan.lib.search import SearchError # Note: This will be deprecated at some point in favour of the # Solr 4 spatial sorting capabilities if search_params.get('sort') == 'spatial desc' and \ p.toolkit.asbool(config.get('ckanext.spatial.use_postgis_sorting', 'False')): if search_params['q'] or search_params['fq']: raise SearchError('Spatial ranking cannot be mixed with other search parameters') # ...because it is too inefficient to use SOLR to filter # results and return the entire set to this class and # after_search do the sorting and paging. extents = bbox_query_ordered(bbox) are_no_results = not extents search_params['extras']['ext_rows'] = search_params['rows'] search_params['extras']['ext_start'] = search_params['start'] # this SOLR query needs to return no actual results since # they are in the wrong order anyway. We just need this SOLR # query to get the count and facet counts. rows = 0 search_params['sort'] = None # SOLR should not sort. # Store the rankings of the results for this page, so for # after_search to construct the correctly sorted results rows = search_params['extras']['ext_rows'] = search_params['rows'] start = search_params['extras']['ext_start'] = search_params['start'] search_params['extras']['ext_spatial'] = [ (extent.package_id, extent.spatial_ranking) \ for extent in extents[start:start+rows]] else: extents = bbox_query(bbox) are_no_results = extents.count() == 0 if are_no_results: # We don't need to perform the search search_params['abort_search'] = True else: # We'll perform the existing search but also filtering by the ids # of datasets within the bbox bbox_query_ids = [extent.package_id for extent in extents] q = search_params.get('q','').strip() or '""' new_q = '%s AND ' % q if q else '' new_q += '(%s)' % ' OR '.join(['id:%s' % id for id in bbox_query_ids]) search_params['q'] = new_q return search_params
def before_search(self,search_params): if 'extras' in search_params and 'ext_bbox' in search_params['extras'] \ and search_params['extras']['ext_bbox']: bbox = validate_bbox(search_params['extras']['ext_bbox']) if not bbox: raise SearchError('Wrong bounding box provided') if search_params.get('sort') == 'spatial desc': if search_params.get('q') or search_params.get('fq'): raise SearchError('Spatial ranking cannot be mixed with other search parameters') # ...because it is too inefficient to use SOLR to filter # results and return the entire set to this class and # after_search do the sorting and paging. extents = bbox_query_ordered(bbox) are_no_results = not extents search_params['extras']['ext_rows'] = search_params.get('rows', 50) search_params['extras']['ext_start'] = search_params.get('start', 0) # this SOLR query needs to return no actual results since # they are in the wrong order anyway. We just need this SOLR # query to get the count and facet counts. rows = 0 search_params['sort'] = None # SOLR should not sort. # Store the rankings of the results for this page, so for # after_search to construct the correctly sorted results rows = search_params['extras']['ext_rows'] = search_params.get('rows', 50) start = search_params['extras']['ext_start'] = search_params.get('start', 0) search_params['extras']['ext_spatial'] = [ (extent.package_id, extent.spatial_ranking) \ for extent in extents[start:start+rows]] else: extents = bbox_query(bbox) are_no_results = extents.count() == 0 if are_no_results: # We don't need to perform the search search_params['abort_search'] = True else: # We'll perform the existing search but also filtering by the ids # of datasets within the bbox bbox_query_ids = [extent.package_id for extent in extents] q = search_params.get('q','').strip() or '""' new_q = '%s AND ' % q if q else '' new_q += '(%s)' % ' OR '.join(['id:%s' % id for id in bbox_query_ids]) search_params['q'] = new_q return search_params
def spatial_query(self): error_400_msg = 'Please provide a suitable bbox parameter [minx,miny,maxx,maxy]' if not 'bbox' in request.params: abort(400,error_400_msg) bbox = validate_bbox(request.params['bbox']) if not bbox: abort(400,error_400_msg) srid = get_srid(request.params.get('crs')) if 'crs' in request.params else None extents = bbox_query(bbox,srid) format = request.params.get('format','') return self._output_results(extents,format)
def spatial_query(register): error_400_msg = \ 'Please provide a suitable bbox parameter [minx,miny,maxx,maxy]' if 'bbox' not in request.args: return _finish_bad_request(error_400_msg) bbox = validate_bbox(request.params['bbox']) if not bbox: return _finish_bad_request(error_400_msg) srid = get_srid(request.args.get('crs')) if 'crs' in \ request.args else None extents = bbox_query(bbox, srid) ids = [extent.package_id for extent in extents] output = dict(count=len(ids), results=ids) return _finish_ok(output)
def spatial_query(self): ''' ''' error_400_msg = \ u'Please provide a suitable bbox parameter [minx,miny,maxx,maxy]' if not u'bbox' in toolkit.request.params: toolkit.abort(400, error_400_msg) bbox = validate_bbox(toolkit.request.params[u'bbox']) if not bbox: toolkit.abort(400, error_400_msg) srid = get_srid(toolkit.request.params.get( u'crs')) if u'crs' in toolkit.request.params else None extents = bbox_query(bbox, srid) format = toolkit.request.params.get(u'format', u'') return self._output_results(extents, format)
def test_query(self): bbox_dict = self.x_values_to_bbox((2, 5)) package_ids = [res.package_id for res in bbox_query(bbox_dict)] package_titles = [model.Package.get(id_).title for id_ in package_ids] assert_equal(set(package_titles), set(('(0, 3)', '(0, 4)', '(4, 5)')))
def test_query(self): bbox_dict = self.x_values_to_bbox((2, 7)) t0 = time.time() q = bbox_query(bbox_dict) t1 = time.time() print 'bbox_query took: ', t1-t0
def test_query(self): bbox_dict = self.x_values_to_bbox((2, 7)) t0 = time.time() bbox_query(bbox_dict) t1 = time.time() print("bbox_query took: ", t1 - t0)
def test_query(self): bbox_dict = self.x_values_to_bbox((2, 5)) package_ids = [res.package_id for res in bbox_query(bbox_dict)] package_titles = [model.Package.get(id_).title for id_ in package_ids] assert (set(package_titles) == set(("(0, 3)", "(0, 4)", "(4, 5)")))