Class: Blacklight::Response::SpellcheckComponent

Inherits:
Component
  • Object
show all
Defined in:
app/components/blacklight/response/spellcheck_component.rb

Overview

Render spellcheck results for a search query

Constant Summary

Constants inherited from Component

Component::EXCLUDE_VARIABLES

Search result helpers collapse

Instance Method Summary collapse

Methods inherited from Component

compiler, config, #inspect

Constructor Details

#initialize(response:, options: nil) ⇒ SpellcheckComponent

Returns a new instance of SpellcheckComponent.

Parameters:

  • response (Blacklight::Response)
  • options (Array<String>) (defaults to: nil)

    explicit spellcheck options to render



9
10
11
12
13
# File 'app/components/blacklight/response/spellcheck_component.rb', line 9

def initialize(response:, options: nil)
  @response = response
  @options = options
  @options ||= options_from_response(@response)
end

Instance Method Details



15
16
17
18
19
# File 'app/components/blacklight/response/spellcheck_component.rb', line 15

def link_to_query(query)
  p = helpers.search_state.to_h.except(:page, :action)
  p[:q] = query
  link_to(query, helpers.search_action_path(p))
end

#render?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'app/components/blacklight/response/spellcheck_component.rb', line 21

def render?
  Array(@options).any? && show_spellcheck_suggestions?(@response)
end

#show_spellcheck_suggestions?(response) ⇒ Boolean

Determine whether to display spellcheck suggestions

Parameters:

Returns:

  • (Boolean)


31
32
33
34
35
36
# File 'app/components/blacklight/response/spellcheck_component.rb', line 31

def show_spellcheck_suggestions? response
  # The spelling response field may be missing from non solr repositories.
  response.total <= helpers.blacklight_config.spell_max &&
    !response.spelling.nil? &&
    response.spelling.words.any?
end