mirror of
https://github.com/wagtail/wagtail.git
synced 2024-11-29 09:33:54 +01:00
Fix search sorting logic in Postgres search backend
This commit is contained in:
parent
6f5f38076a
commit
0736735ac4
@ -246,11 +246,15 @@ class PostgresSearchQuery(BaseSearchQuery):
|
||||
|
||||
def search_in_index(self, queryset, search_query, start, stop):
|
||||
index_entries = self.get_in_index_queryset(queryset, search_query)
|
||||
order_sql = ''
|
||||
values = ['typed_pk']
|
||||
if self.order_by_relevance:
|
||||
index_entries = index_entries.rank(search_query)
|
||||
values.append('rank')
|
||||
order_sql = 'ORDER BY index_entry.rank DESC'
|
||||
index_sql, index_params = get_sql(
|
||||
index_entries.annotate_typed_pk()
|
||||
.values('typed_pk', 'rank')
|
||||
.values(*values)
|
||||
)
|
||||
model_sql, model_params = get_sql(queryset)
|
||||
model = queryset.model
|
||||
@ -258,9 +262,9 @@ class PostgresSearchQuery(BaseSearchQuery):
|
||||
SELECT obj.*
|
||||
FROM (%s) AS index_entry
|
||||
INNER JOIN (%s) AS obj ON obj."%s" = index_entry.typed_pk
|
||||
ORDER BY index_entry.rank DESC
|
||||
%s
|
||||
OFFSET %%s LIMIT %%s;
|
||||
""" % (index_sql, model_sql, get_pk_column(model))
|
||||
""" % (index_sql, model_sql, get_pk_column(model), order_sql)
|
||||
limits = (start, None if stop is None else stop - start)
|
||||
return model._default_manager.using(get_db_alias(queryset)).raw(
|
||||
sql, index_params + model_params + limits)
|
||||
|
Loading…
Reference in New Issue
Block a user