def get_searchqueryset(self, request): query = request.GET.get('q', '') user = self.request.user token = self.request.auth s = FoiRequestDocument.search() if user.is_authenticated: # Either not OAuth or OAuth and valid token if not token and user.is_superuser: # No filters for super users pass elif not token or token.is_valid(['read:request']): s = s.filter( 'bool', should=[ # Bool query in filter context # at least one should clause is required to match. ESQ('term', public=True), ESQ('term', user=user.pk), ]) else: s = s.filter('term', public=True) else: s = s.filter('term', public=True) sqs = SearchQuerySetWrapper(s, FoiRequest) if len(query) > 2: sqs = sqs.set_query( ESQ("multi_match", query=query, fields=['content', 'title', 'description'])) return sqs
def get_searchqueryset(self, request): query = request.GET.get('q', '') sqs = SearchQuerySetWrapper(PublicBodyDocument.search(), PublicBody) if len(query) > 2: sqs = sqs.set_query( Q("multi_match", query=query, fields=['name_auto', 'content'])) filters = { 'jurisdiction': Jurisdiction, 'classification': Classification, 'categories': Category } for key, model in filters.items(): pks = request.GET.getlist(key) if pks: try: obj = model.objects.filter(pk__in=pks) sqs = sqs.filter(**{key: [o.pk for o in obj]}) except ValueError: # Make result set empty, no 0 pk present sqs = sqs.filter(**{key: 0}) sqs = sqs.add_aggregation( ['jurisdiction', 'classification', 'categories']) return sqs
def get_searchqueryset(self, request): query = request.GET.get('q', '') sqs = SearchQuerySetWrapper( PublicBodyDocument.search(), PublicBody ) if len(query) > 2: sqs = sqs.set_query(Q( "multi_match", query=query, fields=['name_auto', 'content'] )) model_filters = { 'jurisdiction': Jurisdiction, 'classification': Classification, 'categories': Category, 'regions': GeoRegion, } for key, model in model_filters.items(): pks = request.GET.getlist(key) if pks: try: obj = model.objects.filter(pk__in=pks) sqs = sqs.filter(**{key: [o.pk for o in obj]}) except ValueError: # Make result set empty, no 0 pk present sqs = sqs.filter(**{key: 0}) other_filters = { 'regions_kind': 'regions_kind' } for key, search_key in other_filters.items(): values = request.GET.getlist(key) if values: sqs = sqs.filter(**{search_key: values}) sqs = sqs.add_aggregation([ 'jurisdiction', 'classification', 'categories', 'regions', ]) return sqs
def get_searchqueryset(self, request): query = request.GET.get('q', '') user = self.request.user token = self.request.auth s = FoiRequestDocument.search() if user.is_authenticated: # Either not OAuth or OAuth and valid token if not token and user.is_superuser: # No filters for super users pass elif not token or token.is_valid(['read:request']): s = s.filter('bool', should=[ # Bool query in filter context # at least one should clause is required to match. ESQ('term', public=True), ESQ('term', user=user.pk), ]) else: s = s.filter('term', public=True) else: s = s.filter('term', public=True) sqs = SearchQuerySetWrapper( s, FoiRequest ) if len(query) > 2: sqs = sqs.set_query(ESQ( "multi_match", query=query, fields=['content', 'title', 'description'] )) return sqs