module Gummi module DbLayer module Document module Search class Filtered include Gummi::DbLayer::Document::Search::Searching attribute :query_string, Gummi::DbLayer::Fields::SanitizedString attribute :query_fields, Array[String], default: ["_all"] attribute :query_filters, Array[Hash], default: [] attribute :facets, Hash, default: {} attribute :sort, Hash, default: {} def to_client_args args = super args[:body] = { query: filtered, facets: facets } args[:body].merge!(sort: sort) if sort.present? args end def query if query_string.present? {query_string: { query: query_string, fields: query_fields }} else {match_all: {}} end end def filtered { 'filtered' => { 'query' => query, 'filter' => process_query_filters }} end def process_query_filters if query_filters.length > 1 {and: query_filters} else query_filters.first end end end end end end end