Module: Blacklight::Searchable

Extended by:
ActiveSupport::Concern
Included in:
Catalog
Defined in:
app/controllers/concerns/blacklight/searchable.rb

Overview

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.

Instance Method Summary collapse

Instance Method Details

#retrieve_document(id) ⇒ Blacklight::Document

This method may be overridden to customize search behavior.

Returns:



35
36
37
# File 'app/controllers/concerns/blacklight/searchable.rb', line 35

def retrieve_document(id)
  search_service.fetch(id)
end

#retrieve_documents(ids) ⇒ Array<Blacklight::Document>

This method may be overridden to customize search behavior.

Returns:



41
42
43
# File 'app/controllers/concerns/blacklight/searchable.rb', line 41

def retrieve_documents(ids)
  search_service.fetch(Array(ids))
end

#retrieve_search_resultsBlacklight::Solr::Response

This method may be overridden to customize search behavior.

Returns:



29
30
31
# File 'app/controllers/concerns/blacklight/searchable.rb', line 29

def retrieve_search_results
  search_service.search_results
end

#search_serviceBlacklight::SearchService



23
24
25
# File 'app/controllers/concerns/blacklight/searchable.rb', line 23

def search_service
  search_service_class.new(config: blacklight_config, search_state: search_state, **search_service_context)
end

#search_service_contextHash

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.

Returns:

  • (Hash)

    a hash of context information to pass through to the search service



49
50
51
# File 'app/controllers/concerns/blacklight/searchable.rb', line 49

def search_service_context
  {}
end

#suggestions_serviceBlacklight::SuggestSearch



54
55
56
# File 'app/controllers/concerns/blacklight/searchable.rb', line 54

def suggestions_service
  Blacklight::SuggestSearch.new(params, search_service.repository).suggestions
end