Sha256: a93ab79b43da1fb9082725b3c3d2d3f093db44413f3fcd747bc3d208a75a4931
Contents?: true
Size: 1.16 KB
Versions: 5
Compression:
Stored size: 1.16 KB
Contents
require 'dynamic_sunspot_search/translator/with' require 'dynamic_sunspot_search/translator/without' module DynamicSunspotSearch module Translator module Facet def self.apply(query_object, options) return unless options.present? query_object.tap do |search| case options when String, Symbol, Array search.facet *options when Hash fields = options.values_at(:field, :fields).flatten.compact exclude_filter = get_exclude_filter(search, options.delete(:exclude)) search.facet(*fields, exclude: exclude_filter) else raise NotImplementedError end end end def self.get_exclude_filter(query_object, options) case options when Array options.map do |option| get_exclude_filter(query_object, option) end.flatten when Hash [ With.apply(query_object, options.delete(:with)), Without.apply(query_object, options.delete(:without)), ].flatten.compact else raise NotImplementedError end end end end end
Version data entries
5 entries across 5 versions & 1 rubygems