Module: Indices
- Defined in:
- lib/indices.rb,
lib/indices/index.rb,
lib/indices/proxy.rb,
lib/indices/concern.rb,
lib/indices/dsl/api.rb,
lib/indices/railtie.rb,
lib/indices/version.rb,
lib/indices/collection.rb,
lib/indices/dsl/search.rb,
lib/indices/pagination.rb,
lib/indices/dsl/mappings.rb,
lib/indices/configuration.rb,
lib/indices/dsl/serializer.rb,
lib/generators/indices/index_generator.rb,
lib/generators/indices/install_generator.rb
Defined Under Namespace
Modules: Concern, Dsl, Generators, Pagination
Classes: Collection, Configuration, Index, Proxy, Railtie
Constant Summary
collapse
- VERSION =
'0.0.1'
Class Method Summary
collapse
Class Method Details
.add(*args) ⇒ Object
48
49
50
51
|
# File 'lib/indices.rb', line 48
def add(*args)
index = Index.new(*args)
registry[index.name] = index
end
|
.build ⇒ Object
62
63
64
65
66
67
68
69
70
|
# File 'lib/indices.rb', line 62
def build
unless client.indices.exists?(index: namespace)
client.indices.create(
index: namespace,
body: { settings: configuration.analysis }
)
end
each &:build
end
|
.client ⇒ Object
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/indices.rb', line 25
def client
@client ||= begin
require 'elasticsearch'
Elasticsearch::Client.new(
hosts: configuration.hosts,
log: configuration.log,
trace: configuration.trace
)
end
end
|
.configuration ⇒ Object
40
41
42
|
# File 'lib/indices.rb', line 40
def configuration
@configuration ||= Configuration.new
end
|
36
37
38
|
# File 'lib/indices.rb', line 36
def configure
yield configuration
end
|
.define(*args, &block) ⇒ Object
44
45
46
|
# File 'lib/indices.rb', line 44
def define(*args, &block)
Proxy.new *args, &block
end
|
.destroy ⇒ Object
81
82
83
84
85
|
# File 'lib/indices.rb', line 81
def destroy
if client.indices.exists?(index: namespace)
client.indices.delete index: namespace
end
end
|
.each(&block) ⇒ Object
58
59
60
|
# File 'lib/indices.rb', line 58
def each(&block)
registry.values.sort.each &block
end
|
.exist?(type) ⇒ Boolean
72
73
74
|
# File 'lib/indices.rb', line 72
def exist?(type)
client.indices.exists? index: namespace, type: type
end
|
.find(name) ⇒ Object
Also known as:
[]
53
54
55
|
# File 'lib/indices.rb', line 53
def find(name)
registry[name]
end
|
.namespace ⇒ Object
21
22
23
|
# File 'lib/indices.rb', line 21
def namespace
"#{Rails.application.class.parent_name} #{Rails.env}".parameterize('_')
end
|
.rebuild ⇒ Object
76
77
78
79
|
# File 'lib/indices.rb', line 76
def rebuild
destroy
build
end
|
.suggest(*args) ⇒ Object
87
88
89
90
91
92
93
|
# File 'lib/indices.rb', line 87
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
|