Merge pull request #1328 from basecamp/search-order
Sort search results by recency
This commit is contained in:
@@ -3,7 +3,7 @@ class Prompts::CardsController < ApplicationController
|
||||
|
||||
def index
|
||||
@cards = if filter_param.present?
|
||||
prepending_exact_matches_by_id(published_cards.mentioning(params[:filter]))
|
||||
prepending_exact_matches_by_id(search_cards)
|
||||
else
|
||||
@cards = published_cards.latest
|
||||
end
|
||||
@@ -18,8 +18,15 @@ class Prompts::CardsController < ApplicationController
|
||||
params[:filter]
|
||||
end
|
||||
|
||||
def search_cards
|
||||
published_cards
|
||||
.mentioning(params[:filter])
|
||||
.reverse_chronologically
|
||||
.limit(MAX_RESULTS)
|
||||
end
|
||||
|
||||
def published_cards
|
||||
Current.user.accessible_cards.published.limit(MAX_RESULTS)
|
||||
Current.user.accessible_cards.published
|
||||
end
|
||||
|
||||
def prepending_exact_matches_by_id(cards)
|
||||
|
||||
@@ -23,6 +23,7 @@ class Search
|
||||
"null as comment_body",
|
||||
"collections.name as collection_name",
|
||||
"cards.creator_id",
|
||||
"cards.created_at",
|
||||
"bm25(cards_search_index, 10.0, 2.0) AS score"
|
||||
].join(","))
|
||||
|
||||
@@ -35,10 +36,11 @@ class Search
|
||||
"snippet(comments_search_index, 0, '#{HIGHLIGHT_OPENING_MARK}', '#{HIGHLIGHT_CLOSING_MARK}', '...', 20) AS comment_body",
|
||||
"collections.name as collection_name",
|
||||
"comments.creator_id",
|
||||
"comments.created_at",
|
||||
"bm25(comments_search_index, 1.0) AS score"
|
||||
].join(","))
|
||||
|
||||
union_sql = "(#{cards.to_sql} UNION #{comments.to_sql}) as search_results"
|
||||
Search::Result.from(union_sql).order(score: :desc)
|
||||
Search::Result.from(union_sql).order(created_at: :desc)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user