Sha256: 69a66383a38618bed8036702e3285765516671030d1f3dfe6fcfb793fe061b64
Contents?: true
Size: 1.44 KB
Versions: 22
Compression:
Stored size: 1.44 KB
Contents
# frozen_string_literal: true module Blacklight module Response # Render spellcheck results for a search query class SpellcheckComponent < Blacklight::Component # @param [Blacklight::Response] response # @param [Array<String>] options explicit spellcheck options to render def initialize(response:, options: nil) @response = response @options = options @options ||= options_from_response(@response) end 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 def render? Array(@options).any? && show_spellcheck_suggestions?(@response) end # @!group Search result helpers ## # Determine whether to display spellcheck suggestions # # @param [Blacklight::Solr::Response] response # @return [Boolean] 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 private def options_from_response(response) if response&.spelling&.collation [response.spelling.collation] elsif response&.spelling&.words response.spelling.words end end end end end
Version data entries
22 entries across 22 versions & 2 rubygems