Sha256: 232df758e2d36887f05de6eccd2e852c8be81f213eb78fb6b89015cca67aa8e6

Contents?: true

Size: 1.71 KB

Versions: 21

Compression:

Stored size: 1.71 KB

Contents

# frozen_string_literal: true

# The Searchable module can be included onto classes that need to initialize a SearchService.
# There are three dependencies you must provide on the including class. Typically these
# would be provided by Blacklight::Controller
#  1. search_state
#  2. blacklight_config
#
# Additionally, the including class may override the search_service_context method to provide
# further context to the SearchService. For example you could override this to provide the
# currently signed in user.
module Blacklight::Searchable
  extend ActiveSupport::Concern

  included do
    # Which class to use for the search service. You can subclass SearchService if you
    # want to override any of the methods (e.g. SearchService#fetch)
    class_attribute :search_service_class
    self.search_service_class = Blacklight::SearchService
  end

  # @return [Blacklight::SearchService]
  def search_service
    search_service_class.new(config: blacklight_config, search_state: search_state, user_params: search_state.to_h, **search_service_context)
  end

  # Override this method on the class that includes Blacklight::Searchable to provide more context to the search service if necessary.
  # For example, if your search builder needs to be aware of the current user, override this method to return a hash including the current user.
  # Then the search builder could use some property about the current user to construct a constraint on the search.
  # @return [Hash] a hash of context information to pass through to the search service
  def search_service_context
    {}
  end

  # @return [Blacklight::SuggestSearch]
  def suggestions_service
    Blacklight::SuggestSearch.new(params, search_service.repository).suggestions
  end
end

Version data entries

21 entries across 21 versions & 2 rubygems

Version Path
blacklight-8.6.1 app/controllers/concerns/blacklight/searchable.rb
blacklight-8.6.0 app/controllers/concerns/blacklight/searchable.rb
blacklight-8.5.1 app/controllers/concerns/blacklight/searchable.rb
blacklight-8.5.0 app/controllers/concerns/blacklight/searchable.rb
blacklight-8.4.0 app/controllers/concerns/blacklight/searchable.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/blacklight-8.3.0/app/controllers/concerns/blacklight/searchable.rb
blacklight-8.3.0 app/controllers/concerns/blacklight/searchable.rb
blacklight-8.2.2 app/controllers/concerns/blacklight/searchable.rb
blacklight-8.2.1 app/controllers/concerns/blacklight/searchable.rb
blacklight-8.2.0 app/controllers/concerns/blacklight/searchable.rb
blacklight-8.1.0 app/controllers/concerns/blacklight/searchable.rb
blacklight-8.0.1 app/controllers/concerns/blacklight/searchable.rb
blacklight-8.0.0 app/controllers/concerns/blacklight/searchable.rb
blacklight-8.0.0.beta8 app/controllers/concerns/blacklight/searchable.rb
blacklight-8.0.0.beta7 app/controllers/concerns/blacklight/searchable.rb
blacklight-8.0.0.beta6 app/controllers/concerns/blacklight/searchable.rb
blacklight-8.0.0.beta5 app/controllers/concerns/blacklight/searchable.rb
blacklight-8.0.0.beta4 app/controllers/concerns/blacklight/searchable.rb
blacklight-8.0.0.beta3 app/controllers/concerns/blacklight/searchable.rb
blacklight-8.0.0.beta2 app/controllers/concerns/blacklight/searchable.rb