Class: CurrentFilterQueryParamsExtractionService

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(solr_fq_extractor, objects_to_merge_solr_params = [], method_names_with_query_params = []) ⇒ CurrentFilterQueryParamsExtractionService

Returns a new instance of CurrentFilterQueryParamsExtractionService.

Parameters:

  • the (lambda)

    function that will convert :f params to :fq

  • an (Array)

    array of receiver objects that will interact with that may have methods which return a hash with keys :f and :q

  • an (Array)

    array of symbols representing messages to send to each of the receiver objects; These messages should return a hash

Raises:

  • (RuntimeError)


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_paramsObject



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