Limit results with just AR in the controller

This commit is contained in:
Jorge Manrubia
2025-06-24 11:08:54 +02:00
parent e59b7fcd18
commit 4710a20836
3 changed files with 6 additions and 7 deletions
+1 -1
View File
@@ -5,7 +5,7 @@ class SearchesController < ApplicationController
end
def show
@search_results = Current.user.search(query_param, max_results: 50)
@search_results = Current.user.search(query_param).limit(50)
@recent_search_queries = Current.user.search_queries.order(created_at: :desc).limit(10)
end
+3 -4
View File
@@ -1,14 +1,13 @@
class Search
attr_reader :user, :query, :max_results
attr_reader :user, :query
def self.table_name_prefix
"search_"
end
def initialize(user, query, max_results: 50)
def initialize(user, query)
@user = user
@query = Query.wrap(query)
@max_results = max_results
end
def results
@@ -39,6 +38,6 @@ class Search
].join(","))
union_sql = "(#{cards.to_sql} UNION #{comments.to_sql}) as search_results"
Search::Result.from(union_sql).order(score: :desc).limit(max_results)
Search::Result.from(union_sql).order(score: :desc)
end
end
+2 -2
View File
@@ -5,8 +5,8 @@ module User::Searcher
has_many :search_queries, class_name: "Search::Query", dependent: :destroy
end
def search(terms, max_results: 50)
Search.new(self, terms, max_results: max_results).results
def search(terms)
Search.new(self, terms).results
end
def remember_search(terms)