Skip to content

Commit

Permalink
add secondary sort_key when using order_by and paginate at the sa…
Browse files Browse the repository at this point in the history
…me time (#7225)
  • Loading branch information
feng000000 authored Aug 13, 2024
1 parent 986fd5b commit 2fe2e35
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions api/controllers/console/datasets/datasets_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,20 @@ def get(self, dataset_id):
.subquery()

query = query.outerjoin(sub_query, sub_query.c.document_id == Document.id) \
.order_by(sort_logic(db.func.coalesce(sub_query.c.total_hit_count, 0)))
.order_by(
sort_logic(db.func.coalesce(sub_query.c.total_hit_count, 0)),
sort_logic(Document.position),
)
elif sort == 'created_at':
query = query.order_by(sort_logic(Document.created_at))
query = query.order_by(
sort_logic(Document.created_at),
sort_logic(Document.position),
)
else:
query = query.order_by(desc(Document.created_at))
query = query.order_by(
desc(Document.created_at),
desc(Document.position),
)

paginated_documents = query.paginate(
page=page, per_page=limit, max_per_page=100, error_out=False)
Expand Down

0 comments on commit 2fe2e35

Please sign in to comment.