Skip to content

Commit

Permalink
158 search with empty text string literally returns all results which…
Browse files Browse the repository at this point in the history
… is expensive (#303)

* Now there is no response to empty query on search.

* Updating env.

---------

Co-authored-by: BuildTools <unconfigured@null.spigotmc.org>
  • Loading branch information
augustjohnson and BuildTools authored Jul 29, 2023
1 parent de09d3f commit 70679e7
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 107 deletions.
202 changes: 97 additions & 105 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 11 additions & 2 deletions api/views.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from django.contrib.auth.models import User, Group

import django_filters
from drf_haystack.viewsets import HaystackViewSet
from rest_framework import viewsets
Expand Down Expand Up @@ -42,16 +43,24 @@ class SearchView(HaystackViewSet):
"""
schema = CustomSchema(
summary={
'/search/': 'Search',
'/search/{id}/': 'Search', # I doubt this is a real endpoint
'/search/': 'Search'
},
tags=['Search']
)
# `index_models` is an optional list of which models you would like to include
# in the search result. You might have several models indexed, and this provides
# a way to filter out those of no interest for this particular view.
# (Translates to `SearchQuerySet().models(*index_models)` behind the scenes.

serializer_class = serializers.AggregateSerializer

def get_queryset(self, *args, **kwargs):
queryset = super().get_queryset(*args, **kwargs)
if not self.request.GET.get('text'):
# Blank text should return results. Improbable query below.
return queryset.filter(wisdom="99999")
return queryset


class UserViewSet(viewsets.ReadOnlyModelViewSet):
"""
Expand Down

0 comments on commit 70679e7

Please sign in to comment.