Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/jobs/communication/website/destroy_website_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def perform(website)
access_token: nil,
repository: nil,
)
Search.remove_data_for_website(website)
University::SearchResult.remove_data_for_website(website)
OBJECTS_NOT_PARANOID.each do |klass|
klass.where(communication_website_id: website.id).destroy_all
end
Expand Down
2 changes: 1 addition & 1 deletion app/jobs/search/build_index_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ class Search::BuildIndexJob < ApplicationJob
queue_as :whales

def perform
Search.build_index
University::SearchResult.build_index
end
end
2 changes: 1 addition & 1 deletion app/models/concerns/searchable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module Searchable

def save_search_data
localizations.each do |l10n|
search = Search.where(
search = University::SearchResult.where(
university: university,
about_object: self,
about_localization: l10n,
Expand Down
6 changes: 3 additions & 3 deletions app/models/university.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
# sso_cert :text
# sso_mapping :jsonb
# sso_name_identifier_format :string
# sso_provider :integer default(0)
# sso_provider :integer default("saml")
# sso_target_url :string
# zipcode :string
# created_at :datetime not null
Expand All @@ -32,7 +32,7 @@
# Indexes
#
# index_universities_on_default_language_id (default_language_id)
# index_universities_on_name (name) USING gin
# index_universities_on_name (name gin_trgm_ops) USING gin
#
# Foreign Keys
#
Expand Down Expand Up @@ -64,7 +64,7 @@ class University < ApplicationRecord
has_many :active_storage_blobs, class_name: 'ActiveStorage::Blob'
has_many :imports, dependent: :destroy
has_many :apps, dependent: :destroy
has_many :search, dependent: :destroy
has_many :search_results, dependent: :destroy

validates :name, presence: true
validates :logo, size: { less_than: 1.megabytes }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,8 @@
# fk_rails_62a3af3969 (extranet_id => communication_extranets.id)
# fk_rails_bab17fceaa (university_id => universities.id)
#
class Search < ApplicationRecord
self.table_name = 'search_index'

class University::SearchResult < ApplicationRecord

SEARCHABLE_MODELS = [
Communication::Extranet,
Communication::Extranet::Document,
Expand Down
4 changes: 2 additions & 2 deletions app/services/osuny/search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ def initialize(term, university, language, website: nil, extranet: nil)
end

def results
term.present? ? build_search_results : Search.none
term.present? ? build_search_results : University::SearchResult.none
end

protected

def build_search_results
results = university.search
results = university.search_results
.for_title(term)
.for_language(language)
.limit(30)
Expand Down
70 changes: 37 additions & 33 deletions app/views/admin/search/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,38 +1,42 @@
<% if @results.none? %>
<p class="text-white text-center"><%= t('admin.search.no_results') %></p>
<% else %>
<div class="row g-2 mb-3">
<%
@results.each do |result|
object = result.about_object
next unless object.present? && can?(:read, object)
# communication_website_post
path_class = object.class.polymorphic_name.parameterize.underscore
# admin_communication_website_post_path
begin
path_name = "admin_#{path_class}_path"
if result.website_id?
path = public_send path_name, { website_id: result.website_id, id: result.about_object_id }
elsif result.extranet_id?
path = public_send path_name, { extranet_id: result.extranet_id, id: result.about_object_id }
else
path = public_send path_name, { id: result.about_object_id }
end
rescue
next
<%
count = 0
%>
<div class="row g-2 mb-3">
<%
@results.each do |result|
object = result.about_object
next unless object.present? && can?(:read, object)
# communication_website_post
path_class = object.class.polymorphic_name.parameterize.underscore
# admin_communication_website_post_path
begin
path_name = "admin_#{path_class}_path"
if result.website_id?
path = public_send path_name, { website_id: result.website_id, id: result.about_object_id }
elsif result.extranet_id?
path = public_send path_name, { extranet_id: result.extranet_id, id: result.about_object_id }
else
path = public_send path_name, { id: result.about_object_id }
end
%>
<div class="col-lg-4 col-md-6">
<div>
<div class="<%= osuny_card_classes(horizontal: true) %>">
<%= osuny_thumbnail_localized object %>
<div class="card-body py-1">
<%= osuny_link_localized object, path, classes: 'stretched-link' %><br>
<span class="small text-muted"><%= object.class.model_name.human %></span>
</div>
count += 1
rescue
next
end
%>
<div class="col-lg-4 col-md-6">
<div>
<div class="<%= osuny_card_classes(horizontal: true) %>">
<%= osuny_thumbnail_localized object %>
<div class="card-body py-1">
<%= osuny_link_localized object, path, classes: 'stretched-link' %><br>
<span class="small text-muted"><%= object.class.model_name.human %></span>
</div>
</div>
</div>
<% end %>
</div>
</div>
<% end %>
</div>

<% if @results.none? || count.zero? %>
<p class="text-white text-center"><%= t('admin.search.no_results') %></p>
<% end %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class RenameSearchIndexToUniversitySearchResults < ActiveRecord::Migration[8.1]
def change
rename_table :search_index, :university_search_results
end
end
Loading