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
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
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.