Пример #1
0
    def get(self, request, *args, **kwargs):
        limit = request.GET.get('limit', 5)
        es_query = {
            'apps': {
                'completion': {
                    'field': 'name_suggest',
                    'size': limit
                },
                'text': request.GET.get('q', '').strip()
            }
        }

        results = S(WebappIndexer).get_es().send_request(
            'GET', [WebappIndexer.get_index(), '_suggest'], body=es_query)

        if 'apps' in results:
            data = results['apps'][0]['options']
        else:
            data = []
        serializer = self.get_serializer(data)
        # This returns a JSON list. Usually this is a bad idea for security
        # reasons, but we don't include any user-specific data, it's fully
        # anonymous, so we're fine.
        return HttpResponse(json.dumps(serializer.data),
                            content_type='application/x-rocketbar+json')
Пример #2
0
 def setUp(self):
     self.webapp = Webapp.objects.get(pk=337141)
     self.request = RequestFactory().get('/')
     RegionMiddleware().process_request(self.request)
     self.reindex(Webapp, 'webapp')
     self.indexer = S(WebappIndexer).filter(id=337141).execute().objects[0]
     self.serializer = SimpleESAppSerializer(self.indexer,
         context={'request': self.request})
Пример #3
0
    def get_query(self, request, base_filters=None):
        form_data = self.get_search_data(request)

        if base_filters is None:
            base_filters = {}
        if form_data.get('status') != 'any':
            base_filters['status'] = form_data.get('status')
        return S(WebappIndexer).filter(**base_filters)
Пример #4
0
 def search(self, request):
     form_data = self.get_search_data(request)
     query = form_data.get('q', '')
     base_filters = {'type': form_data['type']}
     if form_data.get('status') != 'any':
         base_filters['status'] = form_data.get('status')
     qs = S(WebappIndexer).filter(**base_filters)
     qs = self.apply_filters(request, qs, data=form_data)
     qs = apply_reviewer_filters(request, qs, data=form_data)
     page = self.paginate_queryset(qs)
     return self.get_pagination_serializer(page), query