sequel-elasticsearch 0.1.0 → 0.2.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 +5 -5
- data/README.md +2 -2
- data/lib/sequel/plugins/elasticsearch.rb +31 -4
- data/lib/sequel/plugins/elasticsearch/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 3ec57146972164d9b3940a06d43f971d27b578db9a851f8ca90b33f6239b4f72
|
4
|
+
data.tar.gz: 21cc2da346ba2f249956e4b945b8cd4331ef4420eb670efb32ebe387bd3b9676
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d2d560ca5424d915563d586dfc605b6ace4e660283472209a4152464ec165612080afb87d85ece0a1f59ea6884ea4a52f981c961fbb69d574b5f2202930eb936
|
7
|
+
data.tar.gz: f21cd9634945eb35227d0f65a882486c40ccc4c4c368144cb2978baba18376d7902ab553cd49aeeb01cae2738f3df71546aad756e3ee002890764087f617ee2c
|
data/README.md
CHANGED
@@ -68,8 +68,8 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/jrgns/
|
|
68
68
|
|
69
69
|
Features that needs to be built:
|
70
70
|
|
71
|
-
- [
|
72
|
-
- [ ]
|
71
|
+
- [x] An `es` method to search through the data on the cluster.
|
72
|
+
- [ ] Let `es` return an enumerator of `Sequel::Model` instances.
|
73
73
|
- [ ] A rake task to create or suggest mappings for a table.
|
74
74
|
|
75
75
|
## License
|
@@ -19,26 +19,53 @@ module Sequel
|
|
19
19
|
|
20
20
|
module ClassMethods
|
21
21
|
attr_accessor :elasticsearch_opts, :elasticsearch_index, :elasticsearch_type
|
22
|
+
|
23
|
+
def es_client
|
24
|
+
@es_client = ::Elasticsearch::Client.new elasticsearch_opts
|
25
|
+
end
|
26
|
+
|
27
|
+
def es!(query = '', opts = {})
|
28
|
+
opts = {
|
29
|
+
index: elasticsearch_index,
|
30
|
+
type: elasticsearch_type
|
31
|
+
}.merge(opts)
|
32
|
+
query.is_a?(String) ? opts[:q] = query : opts[:body] = query
|
33
|
+
es_client.search opts
|
34
|
+
end
|
35
|
+
|
36
|
+
def es(query = '', opts = {})
|
37
|
+
call_es { es! query, opts }
|
38
|
+
end
|
39
|
+
|
40
|
+
def call_es
|
41
|
+
yield
|
42
|
+
rescue ::Elasticsearch::Transport::Transport::Errors::NotFound, ::Elasticsearch::Transport::Transport::Error => e
|
43
|
+
db.loggers.first.warn e if db.loggers.count.positive?
|
44
|
+
nil
|
45
|
+
rescue Faraday::ConnectionFailed => e
|
46
|
+
db.loggers.first.warn e if db.loggers.count.positive?
|
47
|
+
nil
|
48
|
+
end
|
22
49
|
end
|
23
50
|
|
24
51
|
module InstanceMethods
|
25
52
|
def after_create
|
26
53
|
super
|
27
|
-
index_document
|
54
|
+
self.class.call_es { index_document }
|
28
55
|
end
|
29
56
|
|
30
57
|
def after_destroy
|
31
58
|
super
|
32
|
-
destroy_document
|
59
|
+
self.class.call_es { destroy_document }
|
33
60
|
end
|
34
61
|
|
35
62
|
def after_update
|
36
63
|
super
|
37
|
-
index_document
|
64
|
+
self.class.call_es { index_document }
|
38
65
|
end
|
39
66
|
|
40
67
|
def es_client
|
41
|
-
|
68
|
+
self.class.es_client
|
42
69
|
end
|
43
70
|
|
44
71
|
private
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sequel-elasticsearch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jurgens du Toit
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-02-
|
11
|
+
date: 2018-02-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: elasticsearch
|
@@ -162,7 +162,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
162
162
|
version: '0'
|
163
163
|
requirements: []
|
164
164
|
rubyforge_project:
|
165
|
-
rubygems_version: 2.
|
165
|
+
rubygems_version: 2.7.4
|
166
166
|
signing_key:
|
167
167
|
specification_version: 4
|
168
168
|
summary: A plugin for the Sequel gem to sync data to Elasticsearch.
|