diff --git a/bullet/competitions/views/register.py b/bullet/competitions/views/register.py index 3053ad73..d83aa750 100644 --- a/bullet/competitions/views/register.py +++ b/bullet/competitions/views/register.py @@ -250,12 +250,22 @@ def get_context_data(self, **kwargs): ctx["schools"] = [] query = self.request.GET.get("q") + allowed_types = set( + self.category.educations.values_list( + "grades__school_type_id", flat=True + ).distinct() + ) + allowed_types = ",".join(map(str, allowed_types)) + if query: result = search.client.index("schools").search( query, { - "filter": f"country = '{self.request.COUNTRY_CODE.upper()}' " - f"AND is_hidden = false" + "filter": [ + f"country = '{self.request.COUNTRY_CODE.upper()}'", + "is_hidden = false", + f"types IN [{allowed_types}]", + ] }, ) ctx["schools"] = result["hits"] diff --git a/bullet/education/management/commands/indexschools.py b/bullet/education/management/commands/indexschools.py index e38f1db1..0dbe27e5 100644 --- a/bullet/education/management/commands/indexschools.py +++ b/bullet/education/management/commands/indexschools.py @@ -14,7 +14,7 @@ def handle(self, *args, **options): search.client.index("schools").update_settings( { - "filterableAttributes": ["country", "is_hidden"], + "filterableAttributes": ["country", "is_hidden", "types"], "sortableAttributes": ["name", "address", "country"], "rankingRules": [ "words", diff --git a/bullet/education/models.py b/bullet/education/models.py index b7c82c6e..9c06a6cb 100644 --- a/bullet/education/models.py +++ b/bullet/education/models.py @@ -90,5 +90,6 @@ def for_search(self): "address": self.address, "search": self.search, "country": self.country.code, + "types": [t.id for t in self.types.all()], "is_hidden": self.is_hidden, }