From 4710a2083602e8d5a452acbc03baa6fd1cdecd30 Mon Sep 17 00:00:00 2001 From: Jorge Manrubia Date: Tue, 24 Jun 2025 11:08:54 +0200 Subject: [PATCH] Limit results with just AR in the controller --- app/controllers/searches_controller.rb | 2 +- app/models/search.rb | 7 +++---- app/models/user/searcher.rb | 4 ++-- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/app/controllers/searches_controller.rb b/app/controllers/searches_controller.rb index 6c2c33dee..d32e3fba9 100644 --- a/app/controllers/searches_controller.rb +++ b/app/controllers/searches_controller.rb @@ -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 diff --git a/app/models/search.rb b/app/models/search.rb index 7c0175e7d..06e1571ae 100644 --- a/app/models/search.rb +++ b/app/models/search.rb @@ -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 diff --git a/app/models/user/searcher.rb b/app/models/user/searcher.rb index c8d23b681..a47d9cc96 100644 --- a/app/models/user/searcher.rb +++ b/app/models/user/searcher.rb @@ -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)