class Celsius::Primo::SoapApi::Searcher::SearchBrief::SearchResultTransformation::AddMissingFacets
Public Instance Methods
call()
click to toggle source
handle primo bug where requested facets don't show up in search response
# File lib/celsius/primo/soap_api/searcher/search_brief/search_result_transformation/add_missing_facets.rb, line 8 def call (search_request["facets"] || {}).each do |facet_name, requested_facet| # case 1 - there is no facet at all unless target["facets"][facet_name] if requested_facet["terms"] target["facets"][facet_name] = search_result_terms_facet end end end # case 2 - there is a facet, but the requested facet is not included facet_queries = deep_locate(-> (key, value, object) { key == "match" && value.keys.any? { |key_| key_.start_with?("facet") } }, search_request) facet_queries.each do |facet_query| facet_query["match"].tap do |match| target["facets"][match.keys.first]["terms"].tap do |facet_terms| if facet_terms.none? { |term| term["term"] == match.values.first } facet_terms << { "term" => match.values.first, "count" => 1 } end end end end end
Private Instance Methods
deep_locate(*args)
click to toggle source
# File lib/celsius/primo/soap_api/searcher/search_brief/search_result_transformation/add_missing_facets.rb, line 44 def deep_locate(*args) Hashie::Extensions::DeepLocate.deep_locate(*args) end
search_result_terms_facet(terms = [])
click to toggle source
# File lib/celsius/primo/soap_api/searcher/search_brief/search_result_transformation/add_missing_facets.rb, line 37 def search_result_terms_facet(terms = []) { "_type" => "terms", "terms" => terms } end