What would be the best way to approach the return of a default recordset? If no search results are returned. Currently using below code but it feels not the correct way.
def self.search(params)
puts "SEARCH PARAM ="
puts params
if params
tire.search(load: true, page: params[:page], per_page: 20, :default_operator => 'AND', :use_dis_max => true) do
query do
boolean do
must { string 'gamers:2' } if params[:gamers] == "2"
must { string 'gamers:4' } if params[:gamers] == "4"
end
end
to_curl
end
else
puts "search params not found"
@gamers = Gamers.where(:level => "rookie")
end
end
That looks like you’re only putting in the default set when no params are passed in vs when no search results are returned.
I’d get the results of search and check that !results.total.zero?, then pull the default set accordingly