Class: Blacklight::Suggest::Response

Inherits:
Object
  • Object
show all
Defined in:
app/models/concerns/blacklight/suggest/response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response, request_params, suggest_path, suggester_name) ⇒ Response

Creates a suggest response

Parameters:

  • response (RSolr::HashWithResponse)
  • request_params (Hash)
  • suggest_path (String)
  • suggester_name (String)


14
15
16
17
18
19
# File 'app/models/concerns/blacklight/suggest/response.rb', line 14

def initialize(response, request_params, suggest_path, suggester_name)
  @response = response
  @request_params = request_params
  @suggest_path = suggest_path
  @suggester_name = suggester_name
end

Instance Attribute Details

#request_paramsObject (readonly)

Returns the value of attribute request_params.



6
7
8
# File 'app/models/concerns/blacklight/suggest/response.rb', line 6

def request_params
  @request_params
end

#responseObject (readonly)

Returns the value of attribute response.



6
7
8
# File 'app/models/concerns/blacklight/suggest/response.rb', line 6

def response
  @response
end

#suggest_pathObject (readonly)

Returns the value of attribute suggest_path.



6
7
8
# File 'app/models/concerns/blacklight/suggest/response.rb', line 6

def suggest_path
  @suggest_path
end

#suggester_nameObject (readonly)

Returns the value of attribute suggester_name.



6
7
8
# File 'app/models/concerns/blacklight/suggest/response.rb', line 6

def suggester_name
  @suggester_name
end

Instance Method Details

#suggestionsArray

Trys the suggester response to return suggestions if they are present

Returns:

  • (Array)


25
26
27
# File 'app/models/concerns/blacklight/suggest/response.rb', line 25

def suggestions
  (response.dig(suggest_path, suggester_name, request_params[:q], 'suggestions') || []).uniq
end