module Indexers

Constants

VERSION

Public Class Methods

client() click to toggle source
# File lib/indexers.rb, line 25
def client
  @client ||= begin
    require 'elasticsearch'
    Elasticsearch::Client.new YAML.load_file("#{Rails.root}/config/elasticsearch.yml")[Rails.env]
  end
end
computed_sorts() click to toggle source
# File lib/indexers.rb, line 40
def computed_sorts
  @computed_sorts ||= ComputedSorts.new
end
configuration() click to toggle source
# File lib/indexers.rb, line 36
def configuration
  @configuration ||= Configuration.new
end
configure() { |configuration| ... } click to toggle source
# File lib/indexers.rb, line 32
def configure
  yield configuration
end
define(*args, &block) click to toggle source
# File lib/indexers.rb, line 48
def define(*args, &block)
  Proxy.new *args, &block
end
definitions() click to toggle source
# File lib/indexers.rb, line 44
def definitions
  @definitions ||= Definitions.new
end
index() click to toggle source
# File lib/indexers.rb, line 52
def index
  unless client.indices.exists?(index: namespace)
    client.indices.create(
      index: namespace,
      body: { settings: configuration.analysis }
    )
  end
  definitions.each &:build
end
namespace() click to toggle source
# File lib/indexers.rb, line 21
def namespace
  "#{Rails.application.class.parent_name} #{Rails.env}".parameterize(separator: '_')
end
reindex() click to toggle source
# File lib/indexers.rb, line 62
def reindex
  unindex
  index
end
suggest(*args) click to toggle source
# File lib/indexers.rb, line 73
def suggest(*args)
  response = client.suggest(
    index: namespace,
    body: { suggestions: Dsl::Api.new(args, &configuration.suggestions).to_h }
  )
  response['suggestions'].first['options'].map &:symbolize_keys
end
unindex() click to toggle source
# File lib/indexers.rb, line 67
def unindex
  if client.indices.exists?(index: namespace)
    client.indices.delete index: namespace
  end
end