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.
This commit is contained in:
parent
87bb14482e
commit
66156f2be7
2 changed files with 2 additions and 5 deletions
|
@ -17,6 +17,6 @@ class WagtailSearchFilter(SearchFilter):
|
||||||
return queryset.annotate(relevance=Value(0)).none()
|
return queryset.annotate(relevance=Value(0)).none()
|
||||||
|
|
||||||
filters, query = parse_query_string(search_query)
|
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()
|
return results.get_queryset()
|
||||||
|
|
|
@ -2,7 +2,6 @@ from django.http import HttpResponseRedirect
|
||||||
from django.http.request import HttpRequest
|
from django.http.request import HttpRequest
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
from django.views.generic import RedirectView
|
from django.views.generic import RedirectView
|
||||||
from rest_framework.filters import OrderingFilter
|
|
||||||
from rest_framework.generics import ListAPIView
|
from rest_framework.generics import ListAPIView
|
||||||
from rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
from rest_framework.views import APIView
|
from rest_framework.views import APIView
|
||||||
|
@ -42,10 +41,8 @@ class LMOTFYAPIView(ListAPIView):
|
||||||
Let Me Orange That For You
|
Let Me Orange That For You
|
||||||
"""
|
"""
|
||||||
|
|
||||||
filter_backends = [filters.WagtailSearchFilter, OrderingFilter]
|
filter_backends = [filters.WagtailSearchFilter]
|
||||||
serializer_class = serializers.LMOTFYSerializer
|
serializer_class = serializers.LMOTFYSerializer
|
||||||
ordering_fields = ["title", "date", "relevance"]
|
|
||||||
ordering = ["relevance"]
|
|
||||||
pagination_class = CustomPageNumberPagination
|
pagination_class = CustomPageNumberPagination
|
||||||
|
|
||||||
def get_queryset(self) -> PageQuerySet:
|
def get_queryset(self) -> PageQuerySet:
|
||||||
|
|
Loading…
Reference in a new issue