Sha256: 3d1f5bca60312ac97c6632de31a1fedc1f57d98dc8b733c4d9e64e7814458363

Contents?: true

Size: 1.11 KB

Versions: 1

Compression:

Stored size: 1.11 KB

Contents

require 'dynamic_sunspot_search/translator/facet'
require 'dynamic_sunspot_search/translator/field_list'
require 'dynamic_sunspot_search/translator/order_by'
require 'dynamic_sunspot_search/translator/order_by_function'
require 'dynamic_sunspot_search/translator/paginate'
require 'dynamic_sunspot_search/translator/scope'
require 'dynamic_sunspot_search/translator/text_search'

module DynamicSunspotSearch
  module Translator
    def self.translate(query_object, query_hash)
      query = query_hash.deep_dup.deep_symbolize_keys
      query_object.tap do |search|
        TextSearch.apply(search, query.extract!(:fulltext, :all, :any))
        Scope.apply(search, query.extract!(:with, :without, :any_of, :all_of, :scope))
        FieldList.apply(search, query.delete(:field_list))
        OrderBy.apply(search, query.delete(:order_by))
        OrderByFunction.apply(search, query.delete(:order_by_function))
        Paginate.apply(search, query.delete(:paginate))
        Facet.apply(search, query.delete(:facet))
        raise ArgumentError.new("Unknown keys detected: #{query.keys}") unless query.blank?
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
dynamic_sunspot_search-0.1.2 lib/dynamic_sunspot_search/translator.rb