I think you can try following code (NOT tested). Based on this answer
def index
@tools = Tool.all # I hope you use Rails 4
if params[:search]
tag_tool_ids = @tools.tagged_with(params[:search], any: true, wild: true).pluck(:id) # or pluck('tools.id')
search_tool_ids = @tools.search(params[:search]).pluck(:id) # or pluck('tools.id')
@tools = @tools.where('id IN (?) OR id IN (?)', tag_tool_ids, search_tool_ids
end
end
I hope that this will call one query (but rather complicated and maybe not optimized)