Skip to content

Commit

Permalink
Merge b785aae into 8b90415
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoyne committed Jun 27, 2018
2 parents 8b90415 + b785aae commit bb5e7e6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
17 changes: 3 additions & 14 deletions app/models/blacklight/suggest_search.rb
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
14 changes: 14 additions & 0 deletions lib/blacklight/solr/repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit bb5e7e6

Please sign in to comment.