Sha256: c53bcbce32707a171418416807982c2e81b76b88b66e95f8f821e0d7796ce0a7

Contents?: true

Size: 913 Bytes

Versions: 1

Compression:

Stored size: 913 Bytes

Contents

module Gummi
  module Search
    class Filtered
      include Gummi::Search::Searching

      attribute :query_string,  Gummi::Fields::SanitizedString
      attribute :query_filters, Array[Hash],                    default: []
      attribute :facets,        Hash,                           default: {}

      def to_client_args
        args = {}
        args[:index] = index
        args[:type]  = type if type
        args[:from]  = from
        args[:body]  = {query: filtered, facets: facets }
        args
      end

      def query
        {query_string: { query: query_string}} if query_string.present?
      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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
gummi-0.0.6 lib/gummi/search/filtered.rb