Module: Indexes
- Defined in:
- lib/indexes.rb,
lib/indexes/index.rb,
lib/indexes/proxy.rb,
lib/indexes/concern.rb,
lib/indexes/dsl/api.rb,
lib/indexes/railtie.rb,
lib/indexes/version.rb,
lib/indexes/collection.rb,
lib/indexes/dsl/search.rb,
lib/indexes/pagination.rb,
lib/indexes/definitions.rb,
lib/indexes/dsl/mappings.rb,
lib/indexes/configuration.rb,
lib/indexes/dsl/serialization.rb,
lib/generators/index/index_generator.rb,
lib/generators/indexes/install/install_generator.rb
Defined Under Namespace
Modules: Concern, Dsl, Generators, Pagination
Classes: Collection, Configuration, Definitions, Index, Proxy, Railtie
Constant Summary
collapse
- VERSION =
'4.0.0.2'
Class Method Summary
collapse
Class Method Details
.build ⇒ Object
51
52
53
54
55
56
57
58
59
|
# File 'lib/indexes.rb', line 51
def build
unless client.indices.exists?(index: namespace)
client.indices.create(
index: namespace,
body: { settings: configuration.analysis }
)
end
definitions.each &:build
end
|
.client ⇒ Object
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/indexes.rb', line 24
def client
@client ||= begin
require 'elasticsearch'
Elasticsearch::Client.new(
hosts: configuration.hosts,
log: configuration.log,
trace: configuration.trace
)
end
end
|
.configuration ⇒ Object
39
40
41
|
# File 'lib/indexes.rb', line 39
def configuration
@configuration ||= Configuration.new
end
|
35
36
37
|
# File 'lib/indexes.rb', line 35
def configure
yield configuration
end
|
.define(*args, &block) ⇒ Object
47
48
49
|
# File 'lib/indexes.rb', line 47
def define(*args, &block)
Proxy.new *args, &block
end
|
.definitions ⇒ Object
43
44
45
|
# File 'lib/indexes.rb', line 43
def definitions
@definitions ||= Definitions.new
end
|
.destroy ⇒ Object
70
71
72
73
74
|
# File 'lib/indexes.rb', line 70
def destroy
if client.indices.exists?(index: namespace)
client.indices.delete index: namespace
end
end
|
.exist?(type) ⇒ Boolean
66
67
68
|
# File 'lib/indexes.rb', line 66
def exist?(type)
client.indices.exists? index: namespace, type: type
end
|
.namespace ⇒ Object
20
21
22
|
# File 'lib/indexes.rb', line 20
def namespace
"#{Rails.application.class.parent_name} #{Rails.env}".parameterize('_')
end
|
.rebuild ⇒ Object
61
62
63
64
|
# File 'lib/indexes.rb', line 61
def rebuild
destroy
build
end
|
.suggest(*args) ⇒ Object
76
77
78
79
80
81
82
|
# File 'lib/indexes.rb', line 76
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
|