feat: Sort articles based on views (#7599)

This commit is contained in:
Pranav Raj S
2023-07-24 20:27:43 -07:00
committed by GitHub
parent 703e19304d
commit a6a0e78bbe
6 changed files with 34 additions and 13 deletions

View File

@@ -65,6 +65,7 @@ class Article < ApplicationRecord
scope :search_by_status, ->(status) { where(status: status) if status.present? }
scope :order_by_updated_at, -> { reorder(updated_at: :desc) }
scope :order_by_position, -> { reorder(position: :asc) }
scope :order_by_views, -> { reorder(views: :desc) }
# TODO: if text search slows down https://www.postgresql.org/docs/current/textsearch-features.html#TEXTSEARCH-UPDATE-TRIGGERS
pg_search_scope(