Sha256: 4449cd60d5f034068a595e6f8c1d15a16f84b5e1846f4bd91a002ce643c27232

Contents?: true

Size: 1004 Bytes

Versions: 14

Compression:

Stored size: 1004 Bytes

Contents

module Elastic::Nodes
  class Match < Base
    include Concerns::Boostable
    include Concerns::FieldQuery

    MATCH_MODES = [:boolean, :phrase, :phrase_prefix]

    attr_accessor :query
    attr_reader :mode

    def query=(_query)
      raise ArgumentError, 'query must be a string' unless _query.is_a? String
      @query = _query
    end

    def mode=(_value)
      _value = _value.try(:to_sym)
      raise ArgumentError, 'invalid match mode' if !_value.nil? && !MATCH_MODES.include?(_value)
      @mode = _value
    end

    def clone
      prepare_clone(super)
    end

    def simplify
      prepare_clone(super)
    end

    def render(_options = {})
      hash = { 'query' => @query }
      hash['type'] = @mode.to_s unless @mode.nil? || @mode == :boolean

      { "match" => { render_field(_options) => render_boost(hash) } }
    end

    private

    def prepare_clone(_clone)
      _clone.field = @field
      _clone.query = @query
      _clone.mode = @mode
      _clone
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
elastic-rails-0.8.7 lib/elastic/nodes/match.rb
elastic-rails-0.8.6 lib/elastic/nodes/match.rb
elastic-rails-0.8.5 lib/elastic/nodes/match.rb
elastic-rails-0.8.4 lib/elastic/nodes/match.rb
elastic-rails-0.8.3 lib/elastic/nodes/match.rb
elastic-rails-0.8.2 lib/elastic/nodes/match.rb
elastic-rails-0.8.1 lib/elastic/nodes/match.rb
elastic-rails-0.8.0 lib/elastic/nodes/match.rb
elastic-rails-0.7.0 lib/elastic/nodes/match.rb
elastic-rails-0.6.4 lib/elastic/nodes/match.rb
elastic-rails-0.6.3 lib/elastic/nodes/match.rb
elastic-rails-0.6.2 lib/elastic/nodes/match.rb
elastic-rails-0.6.1 lib/elastic/nodes/match.rb
elastic-rails-0.6.0 lib/elastic/nodes/match.rb