Sha256: c1a3f8f813c84f95292bd9d33aa96dcdeae2aa81eaa03e144aea684e58857c74

Contents?: true

Size: 1.21 KB

Versions: 1

Compression:

Stored size: 1.21 KB

Contents

Indices.configure do |config|

  config.hosts = %w(localhost:9200)
  config.log = false
  config.trace = false

  config.mappings do
    name do
      type 'string'
      fields do
        raw do
          type 'string'
          index 'not_analyzed'
        end
      end
    end
    category type: 'string'
    shop_id type: 'long'
    price type: 'long'
    currency type: 'string'
    product_suggestions do
      type 'completion'
      analyzer 'simple'
      context do
        shop_id do
          type 'category'
          default 'all'
        end
      end
    end
  end

  config.analysis do
    filter do
      ngram do
        type 'nGram'
        min_gram 2
        max_gram 20
      end
    end
  end

  config.suggestions do |name, term, options={}|
    type = name.to_s.singularize
    text (term || '')
    shop = options[:shop]
    completion do
      field "#{type}_suggestions"
      context do
        if shop
          shop_id (shop.id.to_s || 'all')
        end
      end
    end
  end

  config.add_computed_sort :price do |direction|
    _script do
      type 'number'
      script do
        inline "if (_source.currency == 'UYU') { doc['price'].value * 30 }"
      end
      order direction
    end
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
indices-0.0.1 test/dummy/config/initializers/indices.rb