Class: Compass::SearchController
Overview
Instance Method Summary
collapse
Methods included from Cors
#cors
#authenticate, #current_context, #current_context_id, #validate_context
Instance Method Details
#index ⇒ Object
8
9
10
11
12
13
14
15
|
# File 'app/controllers/compass/search_controller.rb', line 8
def index
if params[:q]
results = Compass::Search::Provider.global_search(params.require(:q), current_context)
render json: { results: results }
else
providers
end
end
|
#providers ⇒ Object
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
# File 'app/controllers/compass/search_controller.rb', line 31
def providers
render json: {
context_id: params[:context_id],
providers: available_provider_names.map do |name|
provider_class = find_provider_by_name(name)
base_info = {
name: name,
class_name: provider_class&.name
}
begin
label = provider_class&.new(**current_context)&.label || name.humanize
base_info.merge(label: label)
rescue => e
Rails.logger.warn "Error getting provider info for #{name}: #{e.message}"
base_info.merge(
label: name.humanize,
error: e.message
)
end
end
}
end
|
#show ⇒ Object
17
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'app/controllers/compass/search_controller.rb', line 17
def show
result = Compass::Search::Provider.search(params[:q], params[:provider_name], current_context)
render json: {
provider: params[:provider_name],
context_id: params[:context_id],
**result
}
rescue Compass::Search::UnknownProvider => error
render json: {
error: error.message,
available_providers: error.available_providers
}, status: :not_found
end
|