Class: QuickSearch::SearchController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- ApplicationController
- QuickSearch::SearchController
- Includes:
- DoiTrap, EncodeUtf8, OnCampus, QueryFilter, QueryParser, SearcherConcern, SearcherConfig
- Defined in:
- app/controllers/quick_search/search_controller.rb
Instance Method Summary collapse
- #index ⇒ Object
-
#single_searcher ⇒ Object
TODO: throw error if required files not in place.
-
#xhr_search ⇒ Object
The following searches for individual sections of the page.
Instance Method Details
#index ⇒ Object
16 17 18 19 20 |
# File 'app/controllers/quick_search/search_controller.rb', line 16 def index loaded_searches @common_searches = common_searches http_search end |
#single_searcher ⇒ Object
TODO: throw error if required files not in place
23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'app/controllers/quick_search/search_controller.rb', line 23 def single_searcher searcher_name = params[:searcher_name] searcher_cfg = searcher_config(searcher_name) if searcher_cfg and searcher_cfg.has_key? 'loaded_searches' additional_services = Array.new(searcher_cfg['loaded_searches']) else additional_services = [] end loaded_searches(additional_services) @common_searches = searcher_cfg['common_searches'] || [] #TODO: maybe a default template for single-searcher searches? http_search(searcher_name, "quick_search/search/#{searcher_name}_search") end |
#xhr_search ⇒ Object
The following searches for individual sections of the page. This allows us to do client-side requests in cases where the original server-side request times out or otherwise fails.
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 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 |
# File 'app/controllers/quick_search/search_controller.rb', line 41 def xhr_search endpoint = params[:endpoint] if params[:template] == 'with_paging' template = 'xhr_response_with_paging' else template = 'xhr_response' end @query = params_q_scrubbed @page = page @per_page = per_page(endpoint) @offset = offset(@page,@per_page) http_client = HTTPClient.new update_searcher_timeout(http_client, endpoint, true) benchmark "%s xhr #{endpoint}" % CGI.escape(@query.to_str) do klass = "QuickSearch::#{endpoint.camelize}Searcher".constantize searcher = klass.new(http_client, extracted_query(params_q_scrubbed), @per_page, @offset, @page, on_campus?(ip), extracted_scope(params_q_scrubbed)) searcher.search searcher_partials = {} searcher_cfg = searcher_config(endpoint) unless searcher_cfg.blank? services = searcher_cfg['services'].blank? ? [] : searcher_cfg['services'] else services = [] end services << endpoint respond_to do |format| format.html { services.each do |service| service_template = render_to_string( :partial => "quick_search/search/#{template}", :layout => false, :locals => { module_display_name: t("#{endpoint}_search.display_name"), searcher: searcher, search: '', service_name: service }) searcher_partials[service] = service_template end render :json => searcher_partials } format.json { # prevents openstruct object from results being nested inside tables # See: http://stackoverflow.com/questions/7835047/collecting-hashes-into-openstruct-creates-table-entry result_list = [] searcher.results.each do |result| result_list << result.to_h end render :json => { :endpoint => endpoint, :per_page => @per_page.to_s, :page => @page.to_s, :total => searcher.total, :results => result_list } } end end end |