def test_query_ordered(self):
     ''' '''
     bbox_dict = self.x_values_to_bbox((2, 7))
     t0 = time.time()
     q = bbox_query_ordered(bbox_dict)
     t1 = time.time()
     print u'bbox_query_ordered took: ', t1 - t0
Beispiel #2
0
 def test_query(self):
     bbox_dict = self.x_values_to_bbox((2, 7))
     q = bbox_query_ordered(bbox_dict)
     package_ids = [res.package_id for res in q]
     package_titles = [model.Package.get(id_).title for id_ in package_ids]
     # check the right items are returned
     assert_equal(set(package_titles), set(("(0, 9)", "(1, 8)", "(2, 7)", "(3, 6)", "(4, 5)")))
     # check the order is good
     assert_equal(package_titles, ["(2, 7)", "(1, 8)", "(3, 6)", "(0, 9)", "(4, 5)"])
Beispiel #3
0
 def test_query(self):
     bbox_dict = self.x_values_to_bbox((2, 7))
     q = bbox_query_ordered(bbox_dict)
     package_ids = [res.package_id for res in q]
     package_titles = [model.Package.get(id_).title for id_ in package_ids]
     # check the right items are returned
     assert_equal(set(package_titles),
                  set(('(0, 9)', '(1, 8)', '(2, 7)', '(3, 6)', '(4, 5)')))
     # check the order is good
     assert_equal(package_titles,
                  ['(2, 7)', '(1, 8)', '(3, 6)', '(0, 9)', '(4, 5)'])
Beispiel #4
0
    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 test_query(self):
     bbox_dict = self.x_values_to_bbox((2, 7))
     q = bbox_query_ordered(bbox_dict)
     package_ids = [res.package_id for res in q]
     package_titles = [model.Package.get(id_).title for id_ in package_ids]
     # check the right items are returned
     assert (set(package_titles) == set(
         ("(0, 9)", "(1, 8)", "(2, 7)", "(3, 6)", "(4, 5)")))
     # check the order is good
     assert (package_titles == [
         "(2, 7)", "(1, 8)", "(3, 6)", "(0, 9)", "(4, 5)"
     ])
Beispiel #6
0
    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
Beispiel #7
0
    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
Beispiel #8
0
    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 test_query_ordered(self):
     bbox_dict = self.x_values_to_bbox((2, 7))
     t0 = time.time()
     q = bbox_query_ordered(bbox_dict)
     t1 = time.time()
     print 'bbox_query_ordered took: ', t1-t0
Beispiel #10
0
 def test_query_ordered(self):
     bbox_dict = self.x_values_to_bbox((2, 7))
     t0 = time.time()
     bbox_query_ordered(bbox_dict)
     t1 = time.time()
     print("bbox_query_ordered took: ", t1 - t0)