-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathsearch_controller.rb
More file actions
68 lines (55 loc) · 2.08 KB
/
Copy pathsearch_controller.rb
File metadata and controls
68 lines (55 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# The controller for actions related to searchable models
class SearchController < ApplicationController
PAGE_SIZE = 30
before_action :set_breadcrumbs
# GET /searches
# GET /searches.json
def index
@results = {}
if TeSS::Config.solr_enabled
search_models.each do |model_name|
model = model_name.constantize
@results[model_name.underscore.pluralize.to_sym] = Sunspot.search(model) do
if Facets.applicable?(:across_all_spaces, model)
Facets.across_all_spaces(self, false, current_user)
end
fulltext search_params
with('end').greater_than(Time.zone.now) if model_name == 'Event'
# Hide failing records
if model.method_defined?(:link_monitor)
unless current_user && current_user.is_admin?
without(:failing, true)
end
end
if model_name == 'User' || model.attribute_method?(:user_requires_approval?)
# TODO: Fix this duplication!
# Hide shadowbanned users and their content from other shadowbanned users and administrators
unless current_user && (current_user.shadowbanned? || current_user.is_admin?)
without(:shadowbanned, true)
end
# Hide unverified users and their content from other shadowbanned users and administrators
unless current_user && (current_user.is_curator? || current_user.is_admin?)
without(:unverified, true)
end
end
paginate page: 1, per_page: PAGE_SIZE
end
end
end
@results.reject! { |_, result| result.total < 1 }
end
private
def search_params
params[:q]
end
def search_models
return @_models if @_models
@_models = ['User']
@_models << 'Event' if feature_enabled?('events')
@_models << 'Material' if feature_enabled?('materials')
@_models << 'Collection' if feature_enabled?('collections')
@_models << 'ContentProvider' if feature_enabled?('content_providers')
@_models << 'Trainer' if feature_enabled?('trainers')
@_models
end
end