Class: Hyrax::SearchService
- Inherits:
-
Object
- Object
- Hyrax::SearchService
- Defined in:
- app/services/hyrax/search_service.rb
Overview
Copied from Blacklight 7
Direct Known Subclasses
Instance Attribute Summary collapse
-
#blacklight_config ⇒ Object
readonly
The blacklight_config + controller are accessed by the search_builder.
-
#context ⇒ Object
readonly
The blacklight_config + controller are accessed by the search_builder.
Instance Method Summary collapse
-
#fetch(id = nil, extra_controller_params = {}) ⇒ Blacklight::Solr::Response, Blacklight::SolrDocument
retrieve a document, given the doc id.
-
#initialize(config:, user_params: nil, search_builder_class: config.search_builder_class, **context) ⇒ SearchService
constructor
A new instance of SearchService.
- #search_builder ⇒ Object
-
#search_results {|search_builder| ... } ⇒ Blacklight::Solr::Response
rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity a solr query method.
Constructor Details
#initialize(config:, user_params: nil, search_builder_class: config.search_builder_class, **context) ⇒ SearchService
7 8 9 10 11 12 |
# File 'app/services/hyrax/search_service.rb', line 7 def initialize(config:, user_params: nil, search_builder_class: config.search_builder_class, **context) @blacklight_config = config @user_params = user_params || {} @search_builder_class = search_builder_class @context = context end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *arguments, &block) ⇒ Object (private)
66 67 68 69 70 71 72 73 74 75 |
# File 'app/services/hyrax/search_service.rb', line 66 def method_missing(method_name, *arguments, &block) if scope&.respond_to?(method_name) Deprecation.warn(self.class, "Calling `#{method_name}` on scope " \ 'is deprecated and will be removed in Blacklight 8. Call #to_h first if you ' \ ' need to use hash methods (or, preferably, use your own SearchState implementation)') scope&.public_send(method_name, *arguments, &block) else super end end |
Instance Attribute Details
#blacklight_config ⇒ Object (readonly)
The blacklight_config + controller are accessed by the search_builder
15 16 17 |
# File 'app/services/hyrax/search_service.rb', line 15 def blacklight_config @blacklight_config end |
#context ⇒ Object (readonly)
The blacklight_config + controller are accessed by the search_builder
15 16 17 |
# File 'app/services/hyrax/search_service.rb', line 15 def context @context end |
Instance Method Details
#fetch(id = nil, extra_controller_params = {}) ⇒ Blacklight::Solr::Response, Blacklight::SolrDocument
retrieve a document, given the doc id
46 47 48 49 50 51 52 |
# File 'app/services/hyrax/search_service.rb', line 46 def fetch(id = nil, extra_controller_params = {}) if id.is_a? Array fetch_many(id, extra_controller_params) else fetch_one(id, extra_controller_params) end end |
#search_builder ⇒ Object
17 18 19 |
# File 'app/services/hyrax/search_service.rb', line 17 def search_builder search_builder_class.new(self) end |
#search_results {|search_builder| ... } ⇒ Blacklight::Solr::Response
rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity a solr query method
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'app/services/hyrax/search_service.rb', line 25 def search_results builder = search_builder.with(user_params) builder.page = user_params[:page] if user_params[:page] builder.rows = (user_params[:per_page] || user_params[:rows]) if user_params[:per_page] || user_params[:rows] builder = yield(builder) if block_given? response = repository.search(builder) if response.grouped? && grouped_key_for_results [response.group(grouped_key_for_results), []] elsif response.grouped? && response.grouped.length == 1 [response.grouped.first, []] else [response, response.documents] end end |