68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
|
# File 'app/controllers/search_results_controller.rb', line 68
def index
authorize! :read, Concept::Base
self.class.prepare_basic_variables(self)
{ t: :type,
q: :query,
l: :languages,
qt: :query_type,
c: :collection_origin,
ds: :datasets }.each do |short, long|
params[long] ||= params[short]
end
request.query_parameters.delete('commit')
request.query_parameters.delete('utf8')
@datasets = init_datasets
@remote_result_collections = []
if params[:query]
languages = []
if params[:languages].respond_to?(:each) && params[:languages].include?('none')
languages << nil
elsif params[:languages].respond_to?(:split)
languages = params[:languages].split(',')
end
unless klass = Iqvoc.searchable_class_names.detect { |key, value| value == params[:type] }.try(:first)
raise "'#{params[:type]}' is not a searchable class! Must be one of " + Iqvoc.searchable_class_names.keys.join(', ')
end
klass = klass.constantize
@results = klass.single_query(params.merge({ languages: languages.flatten }))
.filter { |search_result| result_allowed?(search_result) }
if params[:limit] && Iqvoc.unlimited_search_results
@results = @results.per(params[:limit].to_i)
end
if params[:datasets] && datasets = @datasets.select { |a| params[:datasets].include?(a.name) }
@results = SearchResultCollection.new(@results)
datasets.each do |dataset|
results = dataset.search(params)
if results
@results = @results + results
else
flash.now[:error] ||= []
flash.now[:error] << t('txt.controllers.search_results.remote_source_error', source: dataset)
end
end
@results = @results.sort { |x, y| x.to_s <=> y.to_s }
end
@results = Kaminari.paginate_array(@results)
@results = @results.page(params[:page])
respond_to do |format|
format.html {
if request.['Accept'] == 'text/html; fragment=true'
render template: 'search_results/_result_list', layout: false
else
render :index, layout: with_layout?
end
}
format.any(:ttl, :rdf, :nt)
end
end
end
|