@@ -230,9 +230,10 @@ class MatchOrderedSearchFilter(SearchRankFilter):
230230 https://www.postgresql.org/docs/10/static/functions-matching.html#POSIX-CONSTRAINT-ESCAPES-TABLE
231231 """
232232
233- def __init__ (self , match_order_fields , * args , ** kwargs ):
233+ def __init__ (self , match_order_fields , ordering = None , * args , ** kwargs ):
234234 super ().__init__ (* args , ** kwargs )
235235 self .match_order_fields = match_order_fields
236+ self .ordering = ordering
236237
237238 def get_match_order_lookups (self , lookup_type , value ):
238239 or_queries = [
@@ -258,12 +259,13 @@ def filter(self, qs, value):
258259 output_field = IntegerField (),
259260 )
260261
261- default_ordering = self .model ._meta .ordering
262+ ordering = self . ordering or self .model ._meta .ordering
262263
263264 simple_search_qs = (
264265 qs .filter (self .get_match_order_lookups ("icontains" , value ))
265266 .annotate (match_order = match_order )
266- .order_by ("match_order" , * default_ordering )
267+ # Sort by match pertiance first, then by field values
268+ .order_by ("match_order" , * ordering )
267269 )
268270
269271 if simple_search_qs .exists ():
0 commit comments