elastic_record 4.0.0 → 4.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +3 -6
- data/Gemfile +0 -2
- data/README.md +25 -9
- data/elastic_record.gemspec +1 -1
- data/lib/elastic_record/as_document.rb +41 -0
- data/lib/elastic_record/callbacks.rb +11 -56
- data/lib/elastic_record/connection.rb +1 -1
- data/lib/elastic_record/doctype.rb +43 -0
- data/lib/elastic_record/index/deferred.rb +13 -15
- data/lib/elastic_record/index/documents.rb +23 -13
- data/lib/elastic_record/index/manage.rb +4 -6
- data/lib/elastic_record/index/mapping.rb +7 -26
- data/lib/elastic_record/index/settings.rb +17 -2
- data/lib/elastic_record/index.rb +12 -24
- data/lib/elastic_record/model.rb +14 -4
- data/lib/elastic_record/percolator_model.rb +44 -0
- data/lib/elastic_record/relation.rb +1 -2
- data/lib/elastic_record/searching.rb +5 -1
- data/lib/elastic_record/tasks/index.rake +0 -10
- data/lib/elastic_record.rb +3 -0
- data/test/dummy/app/models/mock_model.rb +108 -0
- data/test/dummy/app/models/project.rb +1 -1
- data/test/dummy/app/models/test_model.rb +1 -102
- data/test/dummy/app/models/test_percolator_model.rb +8 -0
- data/test/dummy/app/models/widget.rb +2 -5
- data/test/dummy/app/models/widget_query.rb +14 -0
- data/test/dummy/config/environments/test.rb +3 -3
- data/test/dummy/config/initializers/elastic_record.rb +1 -1
- data/test/elastic_record/as_document_test.rb +65 -0
- data/test/elastic_record/callbacks_test.rb +6 -81
- data/test/elastic_record/config_test.rb +1 -1
- data/test/elastic_record/doctype_test.rb +45 -0
- data/test/elastic_record/index/documents_test.rb +1 -1
- data/test/elastic_record/index/mapping_test.rb +16 -13
- data/test/elastic_record/index/settings_test.rb +34 -1
- data/test/elastic_record/index_test.rb +7 -15
- data/test/elastic_record/model_test.rb +1 -7
- data/test/elastic_record/percolator_model_test.rb +54 -0
- data/test/elastic_record/relation/batches_test.rb +0 -1
- data/test/elastic_record/relation/delegation_test.rb +0 -1
- data/test/elastic_record/relation/finder_methods_test.rb +0 -1
- data/test/elastic_record/relation_test.rb +0 -2
- data/test/elastic_record/searching_test.rb +7 -0
- metadata +11 -10
- data/lib/elastic_record/index/configurator.rb +0 -18
- data/lib/elastic_record/index/percolator.rb +0 -50
- data/lib/elastic_record/index/warmer.rb +0 -24
- data/lib/elastic_record/relation/admin.rb +0 -13
- data/test/elastic_record/index/configurator_test.rb +0 -18
- data/test/elastic_record/index/percolator_test.rb +0 -45
- data/test/elastic_record/index/warmer_test.rb +0 -20
- data/test/elastic_record/relation/admin_test.rb +0 -28
@@ -6,9 +6,42 @@ class ElasticRecord::Index::SettingsTest < MiniTest::Test
|
|
6
6
|
assert_equal expected, ElasticRecord::Index.new(Widget).settings
|
7
7
|
end
|
8
8
|
|
9
|
+
class ModelWithAnalyzers
|
10
|
+
include TestModel
|
11
|
+
|
12
|
+
doctype.analysis = {
|
13
|
+
"analyzer": {
|
14
|
+
"my_custom_analyzer": {
|
15
|
+
"type": "custom",
|
16
|
+
"tokenizer": "standard"
|
17
|
+
}
|
18
|
+
}
|
19
|
+
}
|
20
|
+
|
21
|
+
elastic_index.settings = {
|
22
|
+
"number_of_shards" => 10
|
23
|
+
}
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_settings
|
27
|
+
expected = {
|
28
|
+
"analysis" => {
|
29
|
+
"analyzer": {
|
30
|
+
"my_custom_analyzer": {
|
31
|
+
"type": "custom",
|
32
|
+
"tokenizer": "standard"
|
33
|
+
}
|
34
|
+
}
|
35
|
+
},
|
36
|
+
"number_of_shards" => 10
|
37
|
+
}
|
38
|
+
|
39
|
+
assert_equal expected, ModelWithAnalyzers.elastic_index.settings
|
40
|
+
end
|
41
|
+
|
9
42
|
private
|
10
43
|
|
11
44
|
def index
|
12
45
|
@index ||= ElasticRecord::Index.new(Widget)
|
13
46
|
end
|
14
|
-
end
|
47
|
+
end
|
@@ -5,12 +5,14 @@ class ElasticRecord::IndexTest < MiniTest::Test
|
|
5
5
|
copied = index.dup
|
6
6
|
|
7
7
|
refute_equal copied.settings.object_id, index.settings.object_id
|
8
|
-
refute_equal copied.mapping.object_id, index.mapping.object_id
|
9
8
|
end
|
10
9
|
|
11
|
-
def
|
10
|
+
def test_doctypes
|
11
|
+
assert_equal [Widget.doctype], index.doctypes
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_alias_name
|
12
15
|
assert_equal 'widgets', index.alias_name
|
13
|
-
assert_equal 'widget', index.type
|
14
16
|
end
|
15
17
|
|
16
18
|
def test_disable
|
@@ -26,19 +28,9 @@ class ElasticRecord::IndexTest < MiniTest::Test
|
|
26
28
|
refute index.disabled
|
27
29
|
end
|
28
30
|
|
29
|
-
|
30
|
-
context = nil
|
31
|
-
|
32
|
-
index.configure do
|
33
|
-
context = self
|
34
|
-
end
|
35
|
-
|
36
|
-
assert_kind_of ElasticRecord::Index::Configurator, context
|
37
|
-
end
|
31
|
+
private
|
38
32
|
|
39
|
-
private;
|
40
|
-
|
41
33
|
def index
|
42
34
|
@index ||= ElasticRecord::Index.new(Widget)
|
43
35
|
end
|
44
|
-
end
|
36
|
+
end
|
@@ -11,13 +11,6 @@ class ElasticRecord::ModelTest < MiniTest::Test
|
|
11
11
|
assert_equal ElasticRecord::Config.connection_options.symbolize_keys, connection.options
|
12
12
|
end
|
13
13
|
|
14
|
-
def test_elastic_relation
|
15
|
-
relation = Widget.elastic_relation
|
16
|
-
|
17
|
-
assert_equal Widget, relation.klass
|
18
|
-
assert_equal Widget.arelastic, relation.arelastic
|
19
|
-
end
|
20
|
-
|
21
14
|
def test_elastic_index
|
22
15
|
index = Widget.elastic_index
|
23
16
|
|
@@ -26,5 +19,6 @@ class ElasticRecord::ModelTest < MiniTest::Test
|
|
26
19
|
|
27
20
|
def test_elastic_index_inheritence
|
28
21
|
refute_equal Widget.elastic_index.object_id, InheritedModel.elastic_index.object_id
|
22
|
+
refute_equal Widget.doctype.object_id, InheritedModel.doctype.object_id
|
29
23
|
end
|
30
24
|
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class ElasticRecord::PercolatorModelTest < MiniTest::Test
|
4
|
+
def test_elastic_index
|
5
|
+
assert_equal [WidgetQuery.doctype, Widget.doctype], index.doctypes
|
6
|
+
refute index.partial_updates
|
7
|
+
assert_equal({}, index.settings)
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_doctype
|
11
|
+
assert_equal ElasticRecord::Doctype.percolator_doctype, WidgetQuery.doctype
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_as_search_document
|
15
|
+
query = WidgetQuery.new(name: 'foo', color: 'red')
|
16
|
+
|
17
|
+
expected = {
|
18
|
+
"query" => {
|
19
|
+
"bool" => {
|
20
|
+
"filter" => {
|
21
|
+
"bool" => {
|
22
|
+
"must" => [
|
23
|
+
{ "term" => { :name=>"foo" } },
|
24
|
+
{ "term" => { :color => "red" } }
|
25
|
+
]
|
26
|
+
}
|
27
|
+
}
|
28
|
+
}
|
29
|
+
}
|
30
|
+
}
|
31
|
+
|
32
|
+
assert_equal expected, query.as_search_document
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_percolate_when_no_hits
|
36
|
+
query = WidgetQuery.create(name: 'foo', color: 'red')
|
37
|
+
should_not_hit = { name: 'bar', color: 'blue' }
|
38
|
+
|
39
|
+
assert_empty WidgetQuery.percolate(should_not_hit)
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_percolate_when_hits
|
43
|
+
query = WidgetQuery.create(color: 'red')
|
44
|
+
should_hit = { name: 'foo', color: 'red' }
|
45
|
+
|
46
|
+
assert_equal [query], WidgetQuery.percolate(should_hit)
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
def index
|
52
|
+
@index ||= WidgetQuery.elastic_index
|
53
|
+
end
|
54
|
+
end
|
@@ -28,14 +28,12 @@ class ElasticRecord::RelationTest < MiniTest::Test
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def test_to_ids
|
31
|
-
Widget.elastic_index.delete_all
|
32
31
|
create_widgets [Widget.new(id: 5, color: 'red'), Widget.new(id: 10, color: 'blue')]
|
33
32
|
|
34
33
|
assert_equal ['5', '10'].to_set, Widget.elastic_relation.to_ids.to_set
|
35
34
|
end
|
36
35
|
|
37
36
|
def test_to_a
|
38
|
-
Widget.elastic_index.delete_all
|
39
37
|
create_widgets [Widget.new(id: 5, color: 'red'), Widget.new(id: 10, color: 'blue')]
|
40
38
|
|
41
39
|
array = Widget.elastic_relation.to_a
|
@@ -1,6 +1,13 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
3
|
class ElasticRecord::SearchingTest < MiniTest::Test
|
4
|
+
def test_elastic_relation
|
5
|
+
relation = Widget.elastic_relation
|
6
|
+
|
7
|
+
assert_equal Widget, relation.klass
|
8
|
+
assert_equal Widget.arelastic, relation.arelastic
|
9
|
+
end
|
10
|
+
|
4
11
|
def test_elastic_search
|
5
12
|
|
6
13
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: elastic_record
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.
|
4
|
+
version: 4.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Infogroup
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2017-
|
12
|
+
date: 2017-08-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: arelastic
|
@@ -54,28 +54,27 @@ files:
|
|
54
54
|
- Rakefile
|
55
55
|
- elastic_record.gemspec
|
56
56
|
- lib/elastic_record.rb
|
57
|
+
- lib/elastic_record/as_document.rb
|
57
58
|
- lib/elastic_record/callbacks.rb
|
58
59
|
- lib/elastic_record/config.rb
|
59
60
|
- lib/elastic_record/connection.rb
|
61
|
+
- lib/elastic_record/doctype.rb
|
60
62
|
- lib/elastic_record/errors.rb
|
61
63
|
- lib/elastic_record/index.rb
|
62
64
|
- lib/elastic_record/index/analyze.rb
|
63
|
-
- lib/elastic_record/index/configurator.rb
|
64
65
|
- lib/elastic_record/index/deferred.rb
|
65
66
|
- lib/elastic_record/index/documents.rb
|
66
67
|
- lib/elastic_record/index/manage.rb
|
67
68
|
- lib/elastic_record/index/mapping.rb
|
68
|
-
- lib/elastic_record/index/percolator.rb
|
69
69
|
- lib/elastic_record/index/settings.rb
|
70
|
-
- lib/elastic_record/index/warmer.rb
|
71
70
|
- lib/elastic_record/json.rb
|
72
71
|
- lib/elastic_record/log_subscriber.rb
|
73
72
|
- lib/elastic_record/lucene.rb
|
74
73
|
- lib/elastic_record/model.rb
|
74
|
+
- lib/elastic_record/percolator_model.rb
|
75
75
|
- lib/elastic_record/railtie.rb
|
76
76
|
- lib/elastic_record/railties/controller_runtime.rb
|
77
77
|
- lib/elastic_record/relation.rb
|
78
|
-
- lib/elastic_record/relation/admin.rb
|
79
78
|
- lib/elastic_record/relation/batches.rb
|
80
79
|
- lib/elastic_record/relation/delegation.rb
|
81
80
|
- lib/elastic_record/relation/finder_methods.rb
|
@@ -98,10 +97,13 @@ files:
|
|
98
97
|
- test/dummy/app/mailers/.keep
|
99
98
|
- test/dummy/app/models/.keep
|
100
99
|
- test/dummy/app/models/concerns/.keep
|
100
|
+
- test/dummy/app/models/mock_model.rb
|
101
101
|
- test/dummy/app/models/project.rb
|
102
102
|
- test/dummy/app/models/test_model.rb
|
103
|
+
- test/dummy/app/models/test_percolator_model.rb
|
103
104
|
- test/dummy/app/models/warehouse.rb
|
104
105
|
- test/dummy/app/models/widget.rb
|
106
|
+
- test/dummy/app/models/widget_query.rb
|
105
107
|
- test/dummy/app/views/layouts/application.html.erb
|
106
108
|
- test/dummy/bin/bundle
|
107
109
|
- test/dummy/bin/rails
|
@@ -135,24 +137,23 @@ files:
|
|
135
137
|
- test/dummy/public/422.html
|
136
138
|
- test/dummy/public/500.html
|
137
139
|
- test/dummy/public/favicon.ico
|
140
|
+
- test/elastic_record/as_document_test.rb
|
138
141
|
- test/elastic_record/callbacks_test.rb
|
139
142
|
- test/elastic_record/config_test.rb
|
140
143
|
- test/elastic_record/connection_test.rb
|
144
|
+
- test/elastic_record/doctype_test.rb
|
141
145
|
- test/elastic_record/index/analyze_test.rb
|
142
|
-
- test/elastic_record/index/configurator_test.rb
|
143
146
|
- test/elastic_record/index/documents_test.rb
|
144
147
|
- test/elastic_record/index/manage_test.rb
|
145
148
|
- test/elastic_record/index/mapping_test.rb
|
146
|
-
- test/elastic_record/index/percolator_test.rb
|
147
149
|
- test/elastic_record/index/settings_test.rb
|
148
|
-
- test/elastic_record/index/warmer_test.rb
|
149
150
|
- test/elastic_record/index_test.rb
|
150
151
|
- test/elastic_record/integration/active_record_test.rb
|
151
152
|
- test/elastic_record/log_subscriber_test.rb
|
152
153
|
- test/elastic_record/lucene_test.rb
|
153
154
|
- test/elastic_record/model_test.rb
|
155
|
+
- test/elastic_record/percolator_model_test.rb
|
154
156
|
- test/elastic_record/railties/controller_runtime_test.rb
|
155
|
-
- test/elastic_record/relation/admin_test.rb
|
156
157
|
- test/elastic_record/relation/batches_test.rb
|
157
158
|
- test/elastic_record/relation/delegation_test.rb
|
158
159
|
- test/elastic_record/relation/finder_methods_test.rb
|
@@ -1,18 +0,0 @@
|
|
1
|
-
module ElasticRecord
|
2
|
-
class Index
|
3
|
-
class Configurator
|
4
|
-
attr_reader :index
|
5
|
-
def initialize(index)
|
6
|
-
@index = index
|
7
|
-
end
|
8
|
-
|
9
|
-
def property(name, options)
|
10
|
-
index.mapping[:properties][name.to_sym] = options
|
11
|
-
end
|
12
|
-
|
13
|
-
def has_percolator!
|
14
|
-
index.has_percolator = true
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
@@ -1,50 +0,0 @@
|
|
1
|
-
module ElasticRecord
|
2
|
-
class Index
|
3
|
-
module Percolator
|
4
|
-
def create_percolator(name, elastic_query)
|
5
|
-
connection.json_put "/#{percolator_name}/.percolator/#{name}", elastic_query
|
6
|
-
end
|
7
|
-
|
8
|
-
def delete_percolator(name)
|
9
|
-
connection.json_delete "/#{percolator_name}/.percolator/#{name}"
|
10
|
-
end
|
11
|
-
|
12
|
-
def percolator_exists?(name)
|
13
|
-
connection.head("/#{percolator_name}/.percolator/#{name}") == '200'
|
14
|
-
end
|
15
|
-
|
16
|
-
def get_percolator(name)
|
17
|
-
json = connection.json_get("/#{percolator_name}/.percolator/#{name}")
|
18
|
-
json['_source'] if json['found']
|
19
|
-
end
|
20
|
-
|
21
|
-
def percolate(document)
|
22
|
-
hits = connection.json_get("/#{percolator_name}/#{type}/_percolate", 'doc' => document)['matches']
|
23
|
-
hits.map { |hits| hits['_id'] }
|
24
|
-
end
|
25
|
-
|
26
|
-
def all_percolators
|
27
|
-
if hits = connection.json_get("/#{percolator_name}/.percolator/_search?q=*&size=500")['hits']
|
28
|
-
hits['hits'].map { |hit| hit['_id'] }
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
def create_percolator_index
|
33
|
-
create(percolator_name) unless exists?(percolator_name)
|
34
|
-
end
|
35
|
-
|
36
|
-
def delete_percolator_index
|
37
|
-
delete(percolator_name) if exists?(percolator_name)
|
38
|
-
end
|
39
|
-
|
40
|
-
def reset_percolators
|
41
|
-
delete_percolator_index
|
42
|
-
create_percolator_index
|
43
|
-
end
|
44
|
-
|
45
|
-
def percolator_name
|
46
|
-
"#{alias_name}_percolator"
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
module ElasticRecord
|
2
|
-
class Index
|
3
|
-
module Warmer
|
4
|
-
def create_warmer(name, elastic_query)
|
5
|
-
connection.json_put "/#{alias_name}/#{type}/_warmer/#{name}", elastic_query
|
6
|
-
end
|
7
|
-
|
8
|
-
def delete_warmer(name)
|
9
|
-
connection.json_delete "/#{alias_name}/_warmer/#{name}"
|
10
|
-
end
|
11
|
-
|
12
|
-
def get_warmer(name)
|
13
|
-
json = connection.json_get("/#{alias_name}/#{type}/_warmer/#{name}")
|
14
|
-
if json.any?
|
15
|
-
json.values.first['warmers'][name]
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
def warmer_exists?(name)
|
20
|
-
!get_warmer(name).nil?
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
@@ -1,13 +0,0 @@
|
|
1
|
-
module ElasticRecord
|
2
|
-
class Relation
|
3
|
-
module Admin
|
4
|
-
def create_percolator(name)
|
5
|
-
klass.elastic_index.create_percolator(name, as_elastic)
|
6
|
-
end
|
7
|
-
|
8
|
-
def create_warmer(name)
|
9
|
-
klass.elastic_index.create_warmer(name, as_elastic)
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
class ElasticRecord::Index::ConfiguratorTest < MiniTest::Test
|
4
|
-
def test_property
|
5
|
-
configurator.property :am_i_cool, type: "boolean"
|
6
|
-
|
7
|
-
expected = {type: "boolean"}
|
8
|
-
assert_equal expected, configurator.index.mapping[:properties][:am_i_cool]
|
9
|
-
end
|
10
|
-
|
11
|
-
private
|
12
|
-
def configurator
|
13
|
-
@configurator ||= begin
|
14
|
-
index = ElasticRecord::Index.new(Widget)
|
15
|
-
ElasticRecord::Index::Configurator.new(index)
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
@@ -1,45 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
class ElasticRecord::Index::PercolatorTest < MiniTest::Test
|
4
|
-
def test_create_percolator
|
5
|
-
index.disable_deferring!
|
6
|
-
|
7
|
-
index.delete_percolator('green') if index.percolator_exists?('green')
|
8
|
-
index.delete_percolator('blue') if index.percolator_exists?('blue')
|
9
|
-
|
10
|
-
index.create_percolator('green', 'query' => {'match' => {'color' => 'green'}})
|
11
|
-
|
12
|
-
assert index.percolator_exists?('green')
|
13
|
-
refute index.percolator_exists?('blue')
|
14
|
-
end
|
15
|
-
|
16
|
-
def test_delete_percolator
|
17
|
-
index.disable_deferring!
|
18
|
-
|
19
|
-
index.create_percolator('green', 'query' => {'match' => {'color' => 'green'}})
|
20
|
-
assert index.percolator_exists?('green')
|
21
|
-
|
22
|
-
index.delete_percolator('green')
|
23
|
-
refute index.percolator_exists?('green')
|
24
|
-
end
|
25
|
-
|
26
|
-
def test_reset_percolators
|
27
|
-
index.disable_deferring!
|
28
|
-
|
29
|
-
index.create_percolator('green', 'query' => {'match' => {'color' => 'green'}})
|
30
|
-
assert index.percolator_exists?('green')
|
31
|
-
|
32
|
-
index.reset_percolators
|
33
|
-
|
34
|
-
refute index.percolator_exists?('green')
|
35
|
-
end
|
36
|
-
|
37
|
-
def test_percolate
|
38
|
-
end
|
39
|
-
|
40
|
-
private
|
41
|
-
|
42
|
-
def index
|
43
|
-
Widget.elastic_index
|
44
|
-
end
|
45
|
-
end
|