Module: Indexers
- Defined in:
- lib/indexers.rb,
lib/indexers/proxy.rb,
lib/indexers/concern.rb,
lib/indexers/dsl/api.rb,
lib/indexers/indexer.rb,
lib/indexers/railtie.rb,
lib/indexers/version.rb,
lib/indexers/collection.rb,
lib/indexers/dsl/search.rb,
lib/indexers/pagination.rb,
lib/indexers/definitions.rb,
lib/indexers/dsl/mappings.rb,
lib/indexers/configuration.rb,
lib/indexers/dsl/traitable.rb,
lib/indexers/computed_sorts.rb,
lib/indexers/dsl/serialization.rb,
lib/indexers/extensions/active_record/base.rb,
lib/generators/indexers/indexer/indexer_generator.rb,
lib/generators/indexers/install/install_generator.rb
Defined Under Namespace
Modules: Concern, Dsl, Extensions, Generators, Pagination
Classes: Collection, ComputedSorts, Configuration, Definitions, Indexer, Proxy, Railtie
Constant Summary
collapse
- VERSION =
'5.1.0'
Class Method Summary
collapse
Class Method Details
.client ⇒ Object
25
26
27
28
29
30
|
# 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 ⇒ Object
40
41
42
|
# File 'lib/indexers.rb', line 40
def computed_sorts
@computed_sorts ||= ComputedSorts.new
end
|
.configuration ⇒ Object
36
37
38
|
# File 'lib/indexers.rb', line 36
def configuration
@configuration ||= Configuration.new
end
|
32
33
34
|
# File 'lib/indexers.rb', line 32
def configure
yield configuration
end
|
.define(*args, &block) ⇒ Object
48
49
50
|
# File 'lib/indexers.rb', line 48
def define(*args, &block)
Proxy.new *args, &block
end
|
.definitions ⇒ Object
44
45
46
|
# File 'lib/indexers.rb', line 44
def definitions
@definitions ||= Definitions.new
end
|
.index ⇒ Object
52
53
54
55
56
57
58
59
60
|
# 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 ⇒ Object
21
22
23
|
# File 'lib/indexers.rb', line 21
def namespace
"#{Rails.application.class.parent_name} #{Rails.env}".parameterize(separator: '_')
end
|
.reindex ⇒ Object
62
63
64
65
|
# File 'lib/indexers.rb', line 62
def reindex
unindex
index
end
|
.suggest(*args) ⇒ Object
73
74
75
76
77
78
79
|
# 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 ⇒ Object
67
68
69
70
71
|
# File 'lib/indexers.rb', line 67
def unindex
if client.indices.exists?(index: namespace)
client.indices.delete index: namespace
end
end
|