From b785aae3c16b82cd915b6fee89aa4995c1fbe3d1 Mon Sep 17 00:00:00 2001 From: Justin Coyne Date: Wed, 27 Jun 2018 07:58:25 -0500 Subject: [PATCH] Move suggest handling into the repository This allows the repository to abstract how suggestion handling happens --- app/models/blacklight/suggest_search.rb | 17 +++-------------- lib/blacklight/solr/repository.rb | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/app/models/blacklight/suggest_search.rb b/app/models/blacklight/suggest_search.rb index 63be2db08d..310075022b 100644 --- a/app/models/blacklight/suggest_search.rb +++ b/app/models/blacklight/suggest_search.rb @@ -1,10 +1,12 @@ # frozen_string_literal: true + module Blacklight class SuggestSearch attr_reader :request_params, :repository ## # @param [Hash] params + # @param [Blacklight::AbstractRepository] repository def initialize(params, repository) @request_params = { q: params[:q] } @repository = repository @@ -15,20 +17,7 @@ def initialize(params, repository) # Blacklight::Suggest::Response # @return [Blacklight::Suggest::Response] def suggestions - Blacklight::Suggest::Response.new suggest_results, request_params, suggest_handler_path - end - - ## - # Query the suggest handler using RSolr::Client::send_and_receive - # @return [RSolr::HashWithResponse] - def suggest_results - repository.connection.send_and_receive(suggest_handler_path, params: request_params) - end - - ## - # @return [String] - def suggest_handler_path - repository.blacklight_config.autocomplete_path + repository.suggest_results(request_params) end end end diff --git a/lib/blacklight/solr/repository.rb b/lib/blacklight/solr/repository.rb index 69d3cc193d..fc7608ad23 100644 --- a/lib/blacklight/solr/repository.rb +++ b/lib/blacklight/solr/repository.rb @@ -22,8 +22,16 @@ def search params = {} send_and_receive blacklight_config.solr_path, params.reverse_merge(qt: blacklight_config.qt) end + # @param [Hash] params + # @return [Blacklight::Suggest::Response] + def suggestions(request_params) + suggest_results = connection.send_and_receive(suggest_handler_path, params: request_params) + Blacklight::Suggest::Response.new suggest_results, request_params, suggest_handler_path + end + ## # Execute a solr query + # TODO: Make this private after we have a way to abstract admin/luke and ping # @see [RSolr::Client#send_and_receive] # @overload find(solr_path, params) # Execute a solr query at the given path with the parameters @@ -51,6 +59,12 @@ def send_and_receive(path, solr_params = {}) private + ## + # @return [String] + def suggest_handler_path + blacklight_config.autocomplete_path + end + def build_connection RSolr.connect(connection_config.merge(adapter: connection_config[:http_adapter])) end