Class: CurrentFilterQueryParamsExtractionService
- Inherits:
-
Object
- Object
- CurrentFilterQueryParamsExtractionService
- Defined in:
- app/services/current_filter_query_params_extraction_service.rb
Overview
The purpose of this class is to consolodate the :q and :fq params for querying SOLR.
Instance Method Summary collapse
- #filter_query_params ⇒ Object
-
#initialize(solr_fq_extractor, objects_to_merge_solr_params = [], method_names_with_query_params = []) ⇒ CurrentFilterQueryParamsExtractionService
constructor
A new instance of CurrentFilterQueryParamsExtractionService.
Constructor Details
#initialize(solr_fq_extractor, objects_to_merge_solr_params = [], method_names_with_query_params = []) ⇒ CurrentFilterQueryParamsExtractionService
Returns a new instance of CurrentFilterQueryParamsExtractionService.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'app/services/current_filter_query_params_extraction_service.rb', line 9 def initialize( solr_fq_extractor, objects_to_merge_solr_params = [], method_names_with_query_params = [] ) raise( RuntimeError, "Expected :solr_fq_extractor for #{self.class} to respond to #call" ) unless solr_fq_extractor.respond_to?(:call) raise( RuntimeError, "Expected :objects_to_merge_solr_params for #{self.class}" << " to respond to #each" ) unless objects_to_merge_solr_params.respond_to?(:each) raise( RuntimeError, "Expected :method_names_with_query_params for #{self.class}" << " to respond to #each" ) unless method_names_with_query_params.respond_to?(:each) @solr_fq_extractor = solr_fq_extractor @objects_to_merge_solr_params = objects_to_merge_solr_params @method_names_with_query_params = method_names_with_query_params end |
Instance Method Details
#filter_query_params ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'app/services/current_filter_query_params_extraction_service.rb', line 37 def filter_query_params f_queries = [] queries = [] @objects_to_merge_solr_params.each do |object| @method_names_with_query_params.each do |method_name| collect_solr_params_from(object, method_name) do |q,fq| queries << q if q f_queries << fq if fq end end end { fq: f_queries.uniq.flatten, q: queries.uniq.flatten.join(" AND ") } end |