diff --git a/app/models/search_request.rb b/app/models/search_request.rb
index f19a4ff8..f1dbab49 100644
--- a/app/models/search_request.rb
+++ b/app/models/search_request.rb
@@ -5,6 +5,7 @@
# Table name: search_requests
#
# id :bigint not null, primary key
+# count :integer default(0), not null
# error :string
# filters :jsonb not null
# page :integer default(1)
@@ -21,4 +22,8 @@ class SearchRequest < ApplicationRecord
def full_criteria
filters.merge(page:)
end
+
+ def empty_page?
+ count.zero?
+ end
end
diff --git a/app/services/video_search.rb b/app/services/video_search.rb
index cad01cc3..3d3e327a 100644
--- a/app/services/video_search.rb
+++ b/app/services/video_search.rb
@@ -8,8 +8,8 @@ def initialize(query, page: 1, filters: {})
end
def videos
- Video.visible.includes(playlist: :topic).search(@query, meilisearch_filters).tap do
- search_request.save
+ Video.visible.includes(playlist: :topic).search(@query, meilisearch_filters).tap do |v|
+ search_request.tap { |s| s.count = v.length }.save
end
rescue MeiliSearch::CommunicationError => e
search_request.update(error: e.message)
diff --git a/app/views/dashboard/searches/show.html.erb b/app/views/dashboard/searches/show.html.erb
index 33088084..cb8544a3 100644
--- a/app/views/dashboard/searches/show.html.erb
+++ b/app/views/dashboard/searches/show.html.erb
@@ -11,7 +11,7 @@
Búsqueda |
Filtros |
- Error |
+ Error |
Fecha |
@@ -28,6 +28,14 @@
title: search.error) %>
<% end %>
+
+ <% if search.empty_page? %>
+ <%= tag(:i,
+ data: { 'bs-toggle': 'tooltip' },
+ class: 'bi bi-database-x',
+ title: t('.no_results')) %>
+ <% end %>
+ |
<%= search.created_at %> |
<% end %>
diff --git a/config/locales/dashboard.es.yml b/config/locales/dashboard.es.yml
index 5bf36b13..9cf64300 100644
--- a/config/locales/dashboard.es.yml
+++ b/config/locales/dashboard.es.yml
@@ -95,6 +95,7 @@ es:
show:
searches: Búsquedas
dashboard: Panel de control
+ no_results: No proporcionó resultados
pending:
tags:
show:
diff --git a/db/migrate/20230928104909_add_result_count_to_search_request.rb b/db/migrate/20230928104909_add_result_count_to_search_request.rb
new file mode 100644
index 00000000..dd99bbe0
--- /dev/null
+++ b/db/migrate/20230928104909_add_result_count_to_search_request.rb
@@ -0,0 +1,7 @@
+# frozen_string_literal: true
+
+class AddResultCountToSearchRequest < ActiveRecord::Migration[7.0]
+ def change
+ add_column :search_requests, :count, :integer, default: 0, null: false
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 8d7bd2ea..d298f22f 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema[7.0].define(version: 2023_09_28_082907) do
+ActiveRecord::Schema[7.0].define(version: 2023_09_28_104909) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@@ -130,6 +130,7 @@
t.integer "page", default: 1
t.jsonb "filters", default: "{}", null: false
t.string "error"
+ t.integer "count", default: 0, null: false
t.index ["filters"], name: "index_search_requests_on_filters", using: :gin
t.index ["query"], name: "index_search_requests_on_query"
end