Class: Skala::PrimoAdapter::Search::ResultTransformation::FixPrimoFacetsBugs

Inherits:
Transformator::Transformation::Step
  • Object
show all
Defined in:
lib/skala/primo_adapter/search/result_transformation/fix_primo_facets_bugs.rb

Instance Method Summary collapse

Instance Method Details

#callObject



7
8
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/skala/primo_adapter/search/result_transformation/fix_primo_facets_bugs.rb', line 7

def call
  # please do not change order of the calls below, because they depend (in parts) on each other
  fix_selected_facets_occur_slightly_different
  fix_selected_facet_value_is_missing
  fix_creationdate_facet_values_out_of_selected_range
  # case 1 - there is no facet at all
  #transformation.search_request.facets.each do |_requested_facet|
  #  binding.pry
  #end
=begin
  request[:body]["facets"].try do |_requested_facets|
    _requested_facets.each do |_facet_name, _requested_facet|
      unless target["facets"][_facet_name]
        if _requested_facet.keys.include?("terms")
          target["facets"][_facet_name] = {
            "_type" => "terms",
            "terms" => []
          }
        end
      end
    end
  end
=end

  # case 2 - there is a facet, but the requested facet is not included
=begin
  deep_locate(
    request,
    -> (_key, _value, _) do
      _key == "match" && _value.keys.any? do |__key|
        __key.start_with?("facet")
      end
    end
  )
  .presence
  .try do |_facet_queries|
    _facet_queries.each do |_facet_query|
      _facet_query["match"].try do |_match_query|
        target["facets"][_match_query.keys.first]["terms"].try do |_target_facet_terms|
          if _target_facet_terms.none? { |_term| _term["term"] == _match_query.values.first }
            _target_facet_terms << {
              "term" => _match_query.values.first,
              "count" => 1
            }
          end
        end
      end
    end
  end
=end
end