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 = SearchQuerySet().models(PublicBody).load_all() if len(query) > 2: sqs = sqs.filter(name_auto=AutoQuery(query)) else: sqs = sqs.all() sqs = sqs.facet('jurisdiction', size=30) juris = request.GET.get('jurisdiction') if juris: sqs = sqs.filter(jurisdiction=juris) sqs = sqs.facet('classification', size=100) classification = request.GET.get('classification') if classification: sqs = sqs.filter(classification=classification) sqs = sqs.facet('categories', size=100) categories = request.GET.getlist('categories') if categories: for cat in categories: sqs = sqs.filter(categories=cat) return SearchQuerySetWrapper(sqs, PublicBody)
def get_searchqueryset(self, request): query = request.GET.get('q', '') sqs = SearchQuerySet().models(FoiRequest).load_all() if len(query) > 2: sqs = sqs.auto_query(query) else: sqs = sqs.none() return SearchQuerySetWrapper(sqs, FoiRequest)
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', '') 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'] )) 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