Sha256: 21684dac168d5a4e72ccdbd7173a2ae3dbfce7218f942b4296c49096a10c32bf

Contents?: true

Size: 1.06 KB

Versions: 3

Compression:

Stored size: 1.06 KB

Contents

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_filters, Array[Hash],                    default: []
          attribute :facets,        Hash,                           default: {}

          def to_client_args
            args = super
            args[:body] = { query: filtered, facets: facets }
            args
          end

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

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
gummi-0.2.2 lib/gummi/db_layer/document/search/filtered.rb
gummi-0.2.1 lib/gummi/db_layer/document/search/filtered.rb
gummi-0.2.0 lib/gummi/db_layer/document/search/filtered.rb