From 66156f2be7aee71ff81915c9fc8ff7b8c254c270 Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Mon, 31 Oct 2022 20:39:36 +0000 Subject: [PATCH] Correctly order LMOTFY endpoint Ordering by "relevance" actually yields the least relevant results first. Remove ordering and assume the most relevant is what's needed. --- website/api/filters.py | 2 +- website/api/views.py | 5 +---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/website/api/filters.py b/website/api/filters.py index e31476c..6e998bd 100644 --- a/website/api/filters.py +++ b/website/api/filters.py @@ -17,6 +17,6 @@ class WagtailSearchFilter(SearchFilter): return queryset.annotate(relevance=Value(0)).none() filters, query = parse_query_string(search_query) - results = queryset.search(query).annotate_score("relevance") + results = queryset.search(query, order_by_relevance=True) return results.get_queryset() diff --git a/website/api/views.py b/website/api/views.py index 30cfa0c..52af7c7 100644 --- a/website/api/views.py +++ b/website/api/views.py @@ -2,7 +2,6 @@ from django.http import HttpResponseRedirect from django.http.request import HttpRequest from django.urls import reverse from django.views.generic import RedirectView -from rest_framework.filters import OrderingFilter from rest_framework.generics import ListAPIView from rest_framework.response import Response from rest_framework.views import APIView @@ -42,10 +41,8 @@ class LMOTFYAPIView(ListAPIView): Let Me Orange That For You """ - filter_backends = [filters.WagtailSearchFilter, OrderingFilter] + filter_backends = [filters.WagtailSearchFilter] serializer_class = serializers.LMOTFYSerializer - ordering_fields = ["title", "date", "relevance"] - ordering = ["relevance"] pagination_class = CustomPageNumberPagination def get_queryset(self) -> PageQuerySet: