Sha256: 24cd411b7fb5ad4d7b90340061e15df917e032bbd7794e3b5f766672ecb87b11

Contents?: true

Size: 934 Bytes

Versions: 1

Compression:

Stored size: 934 Bytes

Contents

module Estella
  class Parser
    def initialize(model)
      @model = model
    end

    # document level boost
    # @see https://www.elastic.co/guide/en/elasticsearch/guide/current/boosting-by-popularity.html
    def boost(name, opts = {})
      fail ArgumentError, 'Boost field is not indexed!' unless @model.indexed_fields.include? name
      fail ArgumentError, 'Please supply a modifier and a factor for your boost!' unless (opts.keys & %i[modifier factor]).length == 2

      @model.field_boost = { boost: { field: name }.merge(opts) }
    end

    # index a field
    def field(name, opts = {})
      using = opts[:using] || name
      analysis = opts[:analysis] & @model.default_analysis_fields.keys
      opts[:fields] ||= Hash[analysis.zip(@model.default_analysis_fields.values_at(*analysis))] if analysis

      @model.indexed_json.merge!(name => using)
      @model.indexed_fields.merge!(name => opts)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
estella-2.0.0 lib/estella/parser.rb