def check_bad_query_data(kwargs):
    solr_search = SolrSearch(interface)
    try:
        solr_search.query(**kwargs).params()
    except SolrError:
        pass
    else:
        assert False
def check_multiple_call_data(arg_kw_list, query_output, filter_output):
    solr_search = SolrSearch(interface)
    q = solr_search.query()
    f = solr_search.query()
    for args, kwargs in arg_kw_list:
        q = q.query(*args, **kwargs)
        f = f.filter(*args, **kwargs)
    qp = q.params()
    fp = f.params()
    check_equal_with_debug(qp, query_output)
    check_equal_with_debug(fp, filter_output)
Esempio n. 3
0
    def search_dataset(self, request, **kwargs):
        """
        Perform a full-text search on only one dataset.

        TKTK -- implement field searches
        TKTK -- implement wildcard + boolean searches
        """
        self.method_check(request, allowed=['get'])
        self.is_authenticated(request)
        self.throttle_check(request)

        if 'pk' in kwargs:
            dataset_id = kwargs['pk']
        else:
            dataset_id = request.GET.get('id')

        d = Dataset.objects.get(id=dataset_id)

        limit = int(request.GET.get('limit', settings.PANDA_DEFAULT_SEARCH_ROWS))
        offset = int(request.GET.get('offset', 0))

        s = SolrSearch(self._solr())
        s = s.query(full_text=request.GET.get('q'))
        s = s.filter(dataset_id=dataset_id)
        s = s.paginate(offset, limit)
        s = s.execute()

        paginator = Paginator(request.GET, s, resource_uri=request.path_info)
        page = paginator.page()

        dataset_url = reverse('api_dispatch_detail', kwargs={'api_name': kwargs['api_name'], 'resource_name': 'dataset', 'pk': dataset_id })

        # Update with attributes from the dataset
        # (Resulting object matches a group from the search endpoint)
        page.update({
            'id': d.id,
            'name': d.name,
            'resource_uri': dataset_url,
            'row_count': d.row_count,
            'schema': d.schema
        })

        objects = []

        for obj in s.result.docs:
            bundle = self.build_bundle(obj=SolrObject(obj), request=request)
            bundle = self.full_dehydrate(bundle)
            objects.append(bundle)

        page['objects'] = objects

        self.log_throttled_access(request)

        return self.create_response(request, page)
Esempio n. 4
0
#!/usr/bin/env python

from sunburnt import SolrInterface
from sunburnt.search import SolrSearch

solr = SolrInterface('http://localhost:8983/solr')
s = SolrSearch(solr)

print 'Testing basic query'

response = s.query(full_text='Education').execute()

print response.result

print 'Testing group query'

response = s.query(full_text='Education').group_by('dataset_id', limit=2, sort='+row').execute()

for k, g in response.result.groups.items():
    print k, g.docs 
Esempio n. 5
0
    def search(self, request, **kwargs):
        """
        An endpoint for performing full-text searches.

        TKTK -- implement field searches
        TKTK -- implement wildcard + boolean searches
        """
        self.method_check(request, allowed=['get'])
        self.is_authenticated(request)
        self.throttle_check(request)

        limit = int(request.GET.get('limit', settings.PANDA_DEFAULT_SEARCH_GROUPS))
        offset = int(request.GET.get('offset', 0))

        s = SolrSearch(self._solr())
        s = s.query(full_text=request.GET.get('q'))
        s = s.group_by('dataset_id', limit=settings.PANDA_DEFAULT_SEARCH_ROWS_PER_GROUP, offset=0, sort='+row')
        s = s.paginate(offset, limit)
        s = s.execute()

        paginator = Paginator(request.GET, s, resource_uri=request.path_info)

        page = paginator.page()

        datasets = []

        for dataset_id, group in s.result.groups.items():
            dataset_url = reverse('api_dispatch_detail', kwargs={'api_name': kwargs['api_name'], 'resource_name': 'dataset', 'pk': dataset_id })
            dataset_search_url = reverse('api_search_dataset', kwargs={'api_name': kwargs['api_name'], 'resource_name': 'dataset', 'pk': dataset_id })

            d = Dataset.objects.get(id=dataset_id)

            dataset = {
                'id': d.id,
                'name': d.name,
                'resource_uri': dataset_url,
                'row_count': d.row_count,
                'schema': d.schema,
                'meta': {
                    'limit': settings.PANDA_DEFAULT_SEARCH_ROWS_PER_GROUP,
                    'next': None,
                    'offset': 0,
                    'previous': None,
                    'total_count': group.numFound
                },
                'objects': []
            }

            if group.numFound > settings.PANDA_DEFAULT_SEARCH_ROWS_PER_GROUP:
                dataset['meta']['next'] = '?'.join([dataset_search_url, 'limit=%i&offset=%i' % (settings.PANDA_DEFAULT_SEARCH_ROWS, settings.PANDA_DEFAULT_SEARCH_ROWS)])

            for obj in group.docs:
                bundle = self.build_bundle(obj=SolrObject(obj), request=request)
                bundle = self.full_dehydrate(bundle)
                dataset['objects'].append(bundle)

            datasets.append(dataset)

        page['objects'] = datasets

        self.log_throttled_access(request)

        return self.create_response(request, page)