appfuel 0.6.16 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/lib/appfuel/initializers/all.rb +1 -0
- data/lib/appfuel/initializers/elastic_search.rb +20 -0
- data/lib/appfuel/storage/elastic_search.rb +2 -0
- data/lib/appfuel/storage/elastic_search/adapter.rb +131 -0
- data/lib/appfuel/storage/elastic_search/repository.rb +40 -0
- data/lib/appfuel/version.rb +1 -1
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7f203455f3ec15e5f035c6f493a6d57289b1f926
|
4
|
+
data.tar.gz: d1142265b211c7f0e5dc8a09f3af8c4c9dba5a58
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5bc464c6ae61b099f779fd6fa43699a27f765a29661fcd28fbef272add7b68cf8f9c84dc4541c584fa931f4dfad5e6aa1ef4da65e45b13c681fc9eb8d774cfa8
|
7
|
+
data.tar.gz: d92bdbfdd7d11bd9309a0f814fa841a3514959c50f03cfc38fcf97da0631849e70609d83b3011de1da4fe1277456c60e181234b0888756428558acc86b21c239
|
data/CHANGELOG.md
CHANGED
@@ -2,9 +2,16 @@
|
|
2
2
|
All notable changes to this project will be documented in this file. (Pending approval) This project adheres to [Semantic Versioning](http://semver.org/). You can read more on this at [keep a change log](http://keepachangelog.com/)
|
3
3
|
|
4
4
|
# [Unreleased]
|
5
|
+
## [[0.6.17]](https://github.com/rsb/appfuel/releases/tag/0.6.17) 2017-10-05
|
6
|
+
### Added
|
7
|
+
- ElasticSearch Storage adapter and repository
|
5
8
|
|
6
9
|
|
7
10
|
# Releases
|
11
|
+
## [[0.7.0]](https://github.com/rsb/appfuel/releases/tag/0.7.0) 2017-10-09
|
12
|
+
### Added
|
13
|
+
- adding elastic search repository and adapater
|
14
|
+
|
8
15
|
## [[0.6.16]](https://github.com/rsb/appfuel/releases/tag/0.6.16) 2017-10-02
|
9
16
|
### Fixed
|
10
17
|
- bootstrapping allow testing to disable initializers, swap out config data
|
@@ -0,0 +1,20 @@
|
|
1
|
+
Appfuel::Initialize.define('global.elastic_search') do |config, container|
|
2
|
+
unless config.key?(:elastic_search)
|
3
|
+
fail "[initializer elastic_search] :elastic_search config not found"
|
4
|
+
end
|
5
|
+
unless config[:elastic_search].key?(:url)
|
6
|
+
fail "[initializer elastic_search] :url not found in :elastic_search"
|
7
|
+
end
|
8
|
+
|
9
|
+
require 'elasticsearch'
|
10
|
+
require 'appfuel/storage/elastic_search'
|
11
|
+
|
12
|
+
es_config = config[:elastic_search]
|
13
|
+
options = { url: es_config[:url] }
|
14
|
+
if es_config[:ssl_cert]
|
15
|
+
options[:transport_options] = { ssl: { ca_file: es_config[:ssl_cert] } }
|
16
|
+
end
|
17
|
+
|
18
|
+
client = Elasticsearch::Client.new options
|
19
|
+
container.register(Appfuel::ElasticSearch::CLIENT_CONTAINER_KEY, client)
|
20
|
+
end
|
@@ -0,0 +1,131 @@
|
|
1
|
+
module Appfuel
|
2
|
+
module ElasticSearch
|
3
|
+
DEFAULT_CONFIG_KEY = 'elastic_search'
|
4
|
+
CLIENT_CONTAINER_KEY = "#{DEFAULT_CONFIG_KEY}.client"
|
5
|
+
|
6
|
+
OPS_INDEX = 'index'
|
7
|
+
OPS_DELETE = 'delete'
|
8
|
+
OPS_UPDATE = 'update'
|
9
|
+
|
10
|
+
VALID_OPERATIONS = [
|
11
|
+
OPS_INDEX,
|
12
|
+
OPS_DELETE,
|
13
|
+
OPS_UPDATE
|
14
|
+
]
|
15
|
+
|
16
|
+
class Adapter
|
17
|
+
include Appfuel::Application::AppContainer
|
18
|
+
|
19
|
+
class << self
|
20
|
+
def container_class_type
|
21
|
+
'elastic_search'
|
22
|
+
end
|
23
|
+
|
24
|
+
def config_key(value = nil)
|
25
|
+
if value.nil?
|
26
|
+
return @config_key ||= DEFAULT_CONFIG_KEY
|
27
|
+
end
|
28
|
+
@config_key = value.to_s
|
29
|
+
end
|
30
|
+
|
31
|
+
def load_config
|
32
|
+
config = app_container[:config]
|
33
|
+
key = config_key.to_s
|
34
|
+
if key.include?('.')
|
35
|
+
keys = key.split('.').map {|k| k.to_sym}
|
36
|
+
else
|
37
|
+
keys = [config_key]
|
38
|
+
end
|
39
|
+
|
40
|
+
@config ||= keys.each.inject(config) do |c, k|
|
41
|
+
unless c.key?(k)
|
42
|
+
fail "[elastic_search] config key (#{k}) not found - #{self}"
|
43
|
+
end
|
44
|
+
c[k]
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def config
|
49
|
+
@config ||= load_config
|
50
|
+
end
|
51
|
+
|
52
|
+
def client
|
53
|
+
@client ||= app_container[CLIENT_CONTAINER_KEY]
|
54
|
+
end
|
55
|
+
|
56
|
+
def index_name(value = nil)
|
57
|
+
return @index_name if value.nil?
|
58
|
+
@index_name = value.to_s
|
59
|
+
end
|
60
|
+
|
61
|
+
def inherited(klass)
|
62
|
+
stage_class_for_registration(klass)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
# Instance methods
|
67
|
+
|
68
|
+
def client
|
69
|
+
self.class.client
|
70
|
+
end
|
71
|
+
|
72
|
+
def index_name
|
73
|
+
self.class.index_name
|
74
|
+
end
|
75
|
+
|
76
|
+
def count(type: nil, body: nil)
|
77
|
+
options = { index: index_name }
|
78
|
+
options[:type] = type unless type.nil?
|
79
|
+
options[:body] = body unless body.nil?
|
80
|
+
client.count options
|
81
|
+
end
|
82
|
+
|
83
|
+
def search(type: nil, body:)
|
84
|
+
options = { index: index_name, body: body }
|
85
|
+
options[:type] = type unless type.nil?
|
86
|
+
client.search options
|
87
|
+
end
|
88
|
+
|
89
|
+
def quick_search(type: nil, query:)
|
90
|
+
options = { index: index_name, q: query }
|
91
|
+
options[:type] = type unless type.nil?
|
92
|
+
client.search options
|
93
|
+
end
|
94
|
+
|
95
|
+
def index_document(type, id, data)
|
96
|
+
client.index(
|
97
|
+
index: index_name,
|
98
|
+
type: type,
|
99
|
+
id: id,
|
100
|
+
data: data
|
101
|
+
)
|
102
|
+
end
|
103
|
+
|
104
|
+
def prepare_operation(operation:, type:, id:, data: {})
|
105
|
+
unless VALID_OPERATIONS.include?(operation)
|
106
|
+
fail "[elastic_search] prepare operation '#{opeartion}' is not valid"
|
107
|
+
end
|
108
|
+
prepare = {}
|
109
|
+
prepare[operation.to_sym] = {
|
110
|
+
_index: index_name,
|
111
|
+
_type: type,
|
112
|
+
_id: id,
|
113
|
+
}
|
114
|
+
prepare[operation.to_sym][:data] = data unless operation == OPS_DELETE
|
115
|
+
prepare
|
116
|
+
end
|
117
|
+
|
118
|
+
def batch_documents(operations)
|
119
|
+
unless operations.is_a?(Array)
|
120
|
+
fail "[elastic_search] operations should be an array"
|
121
|
+
end
|
122
|
+
|
123
|
+
client.bulk body: operations
|
124
|
+
end
|
125
|
+
|
126
|
+
def delete_document(type, id)
|
127
|
+
client.delete index: index_name, type: type, id: id
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module Appfuel
|
2
|
+
module ElasticSearch
|
3
|
+
class Repository < Appfuel::Repository::Base
|
4
|
+
class << self
|
5
|
+
def container_class_type
|
6
|
+
"#{super}.elastic_search"
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def storage_class(domain_name)
|
11
|
+
mapper.storage_class('elastic_search', domain_name)
|
12
|
+
end
|
13
|
+
|
14
|
+
def to_entity(domain_name, storage)
|
15
|
+
super(domain_name, 'elastic_search', storage)
|
16
|
+
end
|
17
|
+
|
18
|
+
def to_storage(domain, opts = {})
|
19
|
+
super(domain, 'elastic_search', opts)
|
20
|
+
end
|
21
|
+
|
22
|
+
def extract_sources(results)
|
23
|
+
results["hits"]["hits"].map { |hit| hit["_source"] }
|
24
|
+
end
|
25
|
+
|
26
|
+
def extract_sources_by_type(results)
|
27
|
+
documents = {}
|
28
|
+
results["hits"]["hits"].each do |hit|
|
29
|
+
documents[hit["_type"]] ||= []
|
30
|
+
documents[hit["_type"]] << hit["_source"]
|
31
|
+
end
|
32
|
+
documents
|
33
|
+
end
|
34
|
+
|
35
|
+
def extract_total(results)
|
36
|
+
results["hits"]["total"]
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/lib/appfuel/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: appfuel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robert Scott-Buccleuch
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-10-
|
11
|
+
date: 2017-10-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -306,6 +306,7 @@ files:
|
|
306
306
|
- lib/appfuel/initializers/all.rb
|
307
307
|
- lib/appfuel/initializers/db.rb
|
308
308
|
- lib/appfuel/initializers/dynamodb.rb
|
309
|
+
- lib/appfuel/initializers/elastic_search.rb
|
309
310
|
- lib/appfuel/initializers/logging.rb
|
310
311
|
- lib/appfuel/initializers/web_api.rb
|
311
312
|
- lib/appfuel/log_formatter.rb
|
@@ -331,6 +332,9 @@ files:
|
|
331
332
|
- lib/appfuel/storage/dynamodb/adapter.rb
|
332
333
|
- lib/appfuel/storage/dynamodb/primary_key.rb
|
333
334
|
- lib/appfuel/storage/dynamodb/repository.rb
|
335
|
+
- lib/appfuel/storage/elastic_search.rb
|
336
|
+
- lib/appfuel/storage/elastic_search/adapter.rb
|
337
|
+
- lib/appfuel/storage/elastic_search/repository.rb
|
334
338
|
- lib/appfuel/storage/file.rb
|
335
339
|
- lib/appfuel/storage/file/base.rb
|
336
340
|
- lib/appfuel/storage/memory.rb
|