elastic_record 4.1.8 → 5.1.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.
Files changed (72) hide show
  1. checksums.yaml +5 -5
  2. data/.travis.yml +15 -8
  3. data/Gemfile +1 -1
  4. data/README.md +29 -21
  5. data/elastic_record.gemspec +1 -1
  6. data/lib/elastic_record.rb +25 -13
  7. data/lib/elastic_record/aggregation_response/aggregation.rb +19 -0
  8. data/lib/elastic_record/aggregation_response/bucket.rb +24 -0
  9. data/lib/elastic_record/aggregation_response/builder.rb +55 -0
  10. data/lib/elastic_record/aggregation_response/has_aggregations.rb +9 -0
  11. data/lib/elastic_record/aggregation_response/multi_bucket_aggregation.rb +9 -0
  12. data/lib/elastic_record/aggregation_response/multi_value_aggregation.rb +6 -0
  13. data/lib/elastic_record/aggregation_response/single_bucket_aggregation.rb +8 -0
  14. data/lib/elastic_record/aggregation_response/single_value_aggregation.rb +7 -0
  15. data/lib/elastic_record/as_document.rb +33 -16
  16. data/lib/elastic_record/callbacks.rb +1 -1
  17. data/lib/elastic_record/config.rb +3 -0
  18. data/lib/elastic_record/connection.rb +4 -4
  19. data/lib/elastic_record/errors.rb +7 -1
  20. data/lib/elastic_record/index.rb +6 -8
  21. data/lib/elastic_record/index/analyze.rb +10 -0
  22. data/lib/elastic_record/index/deferred.rb +2 -2
  23. data/lib/elastic_record/index/documents.rb +42 -29
  24. data/lib/elastic_record/index/manage.rb +6 -8
  25. data/lib/elastic_record/index/mapping.rb +16 -8
  26. data/lib/elastic_record/index/mapping_type.rb +16 -0
  27. data/lib/elastic_record/index/mapping_type_test.rb +18 -0
  28. data/lib/elastic_record/index/settings.rb +6 -17
  29. data/lib/elastic_record/model.rb +2 -14
  30. data/lib/elastic_record/percolator_model.rb +11 -19
  31. data/lib/elastic_record/relation.rb +9 -30
  32. data/lib/elastic_record/relation/batches.rb +5 -3
  33. data/lib/elastic_record/relation/delegation.rb +8 -4
  34. data/lib/elastic_record/relation/finder_methods.rb +8 -0
  35. data/lib/elastic_record/relation/hits.rb +34 -0
  36. data/lib/elastic_record/relation/search_methods.rb +17 -22
  37. data/lib/elastic_record/relation/value_methods.rb +1 -1
  38. data/test/dummy/app/models/project.rb +16 -4
  39. data/test/dummy/app/models/warehouse.rb +5 -16
  40. data/test/dummy/app/models/widget.rb +23 -12
  41. data/test/dummy/app/models/widget_query.rb +1 -0
  42. data/test/dummy/db/migrate/20151211225259_create_warehouses.rb +7 -0
  43. data/test/dummy/db/migrate/20180215140125_create_widgets.rb +11 -0
  44. data/test/dummy/db/schema.rb +10 -3
  45. data/test/elastic_record/aggregation_response/bucket_test.rb +8 -0
  46. data/test/elastic_record/aggregation_response/multi_bucket_aggregation_test.rb +33 -0
  47. data/test/elastic_record/aggregation_response/single_bucket_aggregation_test.rb +15 -0
  48. data/test/elastic_record/as_document_test.rb +55 -29
  49. data/test/elastic_record/callbacks_test.rb +7 -11
  50. data/test/elastic_record/connection_test.rb +3 -16
  51. data/test/elastic_record/index/documents_test.rb +56 -11
  52. data/test/elastic_record/index/manage_test.rb +0 -7
  53. data/test/elastic_record/index/mapping_test.rb +18 -5
  54. data/test/elastic_record/index/settings_test.rb +1 -7
  55. data/test/elastic_record/index_test.rb +0 -4
  56. data/test/elastic_record/integration/active_record_test.rb +6 -9
  57. data/test/elastic_record/model_test.rb +5 -2
  58. data/test/elastic_record/percolator_model_test.rb +25 -11
  59. data/test/elastic_record/relation/batches_test.rb +29 -47
  60. data/test/elastic_record/relation/delegation_test.rb +1 -1
  61. data/test/elastic_record/relation/finder_methods_test.rb +17 -31
  62. data/test/elastic_record/relation/hits_test.rb +49 -0
  63. data/test/elastic_record/relation/search_methods_test.rb +20 -16
  64. data/test/elastic_record/relation_test.rb +19 -50
  65. data/test/helper.rb +7 -3
  66. metadata +20 -9
  67. data/lib/elastic_record/doctype.rb +0 -43
  68. data/lib/elastic_record/json.rb +0 -29
  69. data/lib/elastic_record/name_cache.rb +0 -23
  70. data/test/dummy/db/migrate/20151211225259_create_projects.rb +0 -7
  71. data/test/elastic_record/doctype_test.rb +0 -45
  72. data/test/elastic_record/name_cache_test.rb +0 -16
data/test/helper.rb CHANGED
@@ -1,12 +1,16 @@
1
1
  ENV["RAILS_ENV"] = "test"
2
2
 
3
- require File.expand_path("../../test/dummy/config/environment.rb", __FILE__)
3
+ require 'dummy/config/environment'
4
+ require 'rails/test_help'
5
+ Bundler.require(Rails.env)
4
6
 
5
- require 'minitest/autorun'
6
7
  require 'webmock/minitest'
7
-
8
8
  WebMock.disable_net_connect!(allow_localhost: true)
9
9
 
10
+ def MiniTest.filter_backtrace(bt)
11
+ bt
12
+ end
13
+
10
14
  module MiniTest
11
15
  class Test
12
16
  def setup
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.1.8
4
+ version: 5.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-10-06 00:00:00.000000000 Z
12
+ date: 2018-10-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: arelastic
@@ -54,11 +54,18 @@ files:
54
54
  - Rakefile
55
55
  - elastic_record.gemspec
56
56
  - lib/elastic_record.rb
57
+ - lib/elastic_record/aggregation_response/aggregation.rb
58
+ - lib/elastic_record/aggregation_response/bucket.rb
59
+ - lib/elastic_record/aggregation_response/builder.rb
60
+ - lib/elastic_record/aggregation_response/has_aggregations.rb
61
+ - lib/elastic_record/aggregation_response/multi_bucket_aggregation.rb
62
+ - lib/elastic_record/aggregation_response/multi_value_aggregation.rb
63
+ - lib/elastic_record/aggregation_response/single_bucket_aggregation.rb
64
+ - lib/elastic_record/aggregation_response/single_value_aggregation.rb
57
65
  - lib/elastic_record/as_document.rb
58
66
  - lib/elastic_record/callbacks.rb
59
67
  - lib/elastic_record/config.rb
60
68
  - lib/elastic_record/connection.rb
61
- - lib/elastic_record/doctype.rb
62
69
  - lib/elastic_record/errors.rb
63
70
  - lib/elastic_record/index.rb
64
71
  - lib/elastic_record/index/analyze.rb
@@ -66,12 +73,12 @@ files:
66
73
  - lib/elastic_record/index/documents.rb
67
74
  - lib/elastic_record/index/manage.rb
68
75
  - lib/elastic_record/index/mapping.rb
76
+ - lib/elastic_record/index/mapping_type.rb
77
+ - lib/elastic_record/index/mapping_type_test.rb
69
78
  - lib/elastic_record/index/settings.rb
70
- - lib/elastic_record/json.rb
71
79
  - lib/elastic_record/log_subscriber.rb
72
80
  - lib/elastic_record/lucene.rb
73
81
  - lib/elastic_record/model.rb
74
- - lib/elastic_record/name_cache.rb
75
82
  - lib/elastic_record/percolator_model.rb
76
83
  - lib/elastic_record/railtie.rb
77
84
  - lib/elastic_record/railties/controller_runtime.rb
@@ -79,6 +86,7 @@ files:
79
86
  - lib/elastic_record/relation/batches.rb
80
87
  - lib/elastic_record/relation/delegation.rb
81
88
  - lib/elastic_record/relation/finder_methods.rb
89
+ - lib/elastic_record/relation/hits.rb
82
90
  - lib/elastic_record/relation/merging.rb
83
91
  - lib/elastic_record/relation/none.rb
84
92
  - lib/elastic_record/relation/search_methods.rb
@@ -130,7 +138,8 @@ files:
130
138
  - test/dummy/config/locales/en.yml
131
139
  - test/dummy/config/routes.rb
132
140
  - test/dummy/config/secrets.yml
133
- - test/dummy/db/migrate/20151211225259_create_projects.rb
141
+ - test/dummy/db/migrate/20151211225259_create_warehouses.rb
142
+ - test/dummy/db/migrate/20180215140125_create_widgets.rb
134
143
  - test/dummy/db/schema.rb
135
144
  - test/dummy/lib/assets/.keep
136
145
  - test/dummy/log/.keep
@@ -138,11 +147,13 @@ files:
138
147
  - test/dummy/public/422.html
139
148
  - test/dummy/public/500.html
140
149
  - test/dummy/public/favicon.ico
150
+ - test/elastic_record/aggregation_response/bucket_test.rb
151
+ - test/elastic_record/aggregation_response/multi_bucket_aggregation_test.rb
152
+ - test/elastic_record/aggregation_response/single_bucket_aggregation_test.rb
141
153
  - test/elastic_record/as_document_test.rb
142
154
  - test/elastic_record/callbacks_test.rb
143
155
  - test/elastic_record/config_test.rb
144
156
  - test/elastic_record/connection_test.rb
145
- - test/elastic_record/doctype_test.rb
146
157
  - test/elastic_record/index/analyze_test.rb
147
158
  - test/elastic_record/index/documents_test.rb
148
159
  - test/elastic_record/index/manage_test.rb
@@ -153,12 +164,12 @@ files:
153
164
  - test/elastic_record/log_subscriber_test.rb
154
165
  - test/elastic_record/lucene_test.rb
155
166
  - test/elastic_record/model_test.rb
156
- - test/elastic_record/name_cache_test.rb
157
167
  - test/elastic_record/percolator_model_test.rb
158
168
  - test/elastic_record/railties/controller_runtime_test.rb
159
169
  - test/elastic_record/relation/batches_test.rb
160
170
  - test/elastic_record/relation/delegation_test.rb
161
171
  - test/elastic_record/relation/finder_methods_test.rb
172
+ - test/elastic_record/relation/hits_test.rb
162
173
  - test/elastic_record/relation/merging_test.rb
163
174
  - test/elastic_record/relation/none_test.rb
164
175
  - test/elastic_record/relation/search_methods_test.rb
@@ -185,7 +196,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
185
196
  version: 1.8.11
186
197
  requirements: []
187
198
  rubyforge_project:
188
- rubygems_version: 2.6.13
199
+ rubygems_version: 2.7.6
189
200
  signing_key:
190
201
  specification_version: 4
191
202
  summary: An Elasticsearch querying ORM
@@ -1,43 +0,0 @@
1
- module ElasticRecord
2
- class Doctype
3
- attr_accessor :name, :mapping, :analysis
4
-
5
- DEFAULT_MAPPING = {
6
- properties: {
7
- },
8
- _all: {
9
- enabled: false
10
- }
11
- }
12
-
13
- PERCOLATOR_MAPPING = {
14
- properties: {
15
- query: {
16
- type: "percolator"
17
- }
18
- }
19
- }
20
-
21
- def self.percolator_doctype
22
- new('queries', PERCOLATOR_MAPPING)
23
- end
24
-
25
- def initialize(name, mapping = DEFAULT_MAPPING.deep_dup)
26
- @name = name
27
- @mapping = mapping
28
- @analysis = {}
29
- end
30
-
31
- def mapping=(custom_mapping)
32
- mapping.deep_merge!(custom_mapping)
33
- end
34
-
35
- def analysis=(custom_analysis)
36
- analysis.deep_merge!(custom_analysis)
37
- end
38
-
39
- def ==(other)
40
- name == other.name && mapping == other.mapping && analysis == other.analysis
41
- end
42
- end
43
- end
@@ -1,29 +0,0 @@
1
- module ElasticRecord
2
- module JSON
3
- class << self
4
- def parser
5
- @@parser ||= :active_support
6
- end
7
-
8
- def parser=(value)
9
- @@parser = value
10
- end
11
-
12
- def decode(json)
13
- if ElasticRecord::JSON.parser == :oj
14
- Oj.compat_load(json)
15
- else
16
- ActiveSupport::JSON.decode(json)
17
- end
18
- end
19
-
20
- def encode(data)
21
- if ElasticRecord::JSON.parser == :oj
22
- Oj.dump(data, mode: :compat, use_as_json: true)
23
- else
24
- ActiveSupport::JSON.encode(data)
25
- end
26
- end
27
- end
28
- end
29
- end
@@ -1,23 +0,0 @@
1
- module ElasticRecord
2
- module NameCache
3
- extend ActiveSupport::Concern
4
-
5
- included do
6
- class_attribute :cached_index_name
7
- class_attribute :index_name_cache_time
8
- self.index_name_cache_time = 0
9
- end
10
-
11
- class_methods do
12
- def current_index_name
13
- if (Time.now - index_name_cache_time) < 60
14
- cached_index_name
15
- else
16
- self.index_name_cache_time = Time.now
17
- aliased_names = elastic_connection.json_get("/_alias/#{elastic_index.alias_name}").keys
18
- self.cached_index_name = aliased_names.first
19
- end
20
- end
21
- end
22
- end
23
- end
@@ -1,7 +0,0 @@
1
- class CreateProjects < ActiveRecord::Migration
2
- def change
3
- create_table :projects do |t|
4
- t.string :name, null: false
5
- end
6
- end
7
- end
@@ -1,45 +0,0 @@
1
- require 'helper'
2
-
3
- class ElasticRecord::DoctypeTest < MiniTest::Test
4
- def test_default_mapping
5
- doctype = ElasticRecord::Doctype.new('widget')
6
-
7
- refute_nil doctype.mapping[:properties]
8
- end
9
-
10
- def test_default_analysis
11
- doctype = ElasticRecord::Doctype.new('widget')
12
-
13
- assert_empty doctype.analysis
14
- end
15
-
16
- def test_merge_mapping
17
- doctype = ElasticRecord::Doctype.new('widget')
18
- doctype.mapping[:properties] = {
19
- color: { type: 'string' },
20
- name: { type: 'string' }
21
- }
22
-
23
- custom = { properties: { color: { type: 'integer' } }}
24
- doctype.mapping = custom
25
-
26
- expected = {
27
- properties: {
28
- color: { type: 'integer' },
29
- name: { type: 'string' }
30
- },
31
- _all: {
32
- enabled: false
33
- }
34
- }
35
-
36
- assert_equal expected, doctype.mapping
37
- end
38
-
39
- def test_percolator_doctype
40
- doctype = ElasticRecord::Doctype.percolator_doctype
41
-
42
- assert_equal 'queries', doctype.name
43
- assert_equal ElasticRecord::Doctype::PERCOLATOR_MAPPING, doctype.mapping
44
- end
45
- end
@@ -1,16 +0,0 @@
1
- require 'helper'
2
-
3
- class ElasticRecord::NameCacheTest < MiniTest::Test
4
- class Felon
5
- include TestModel
6
- end
7
-
8
- def test_index_name
9
- begin
10
- Felon.elastic_index.create_and_deploy("felons_datestamp")
11
- assert_equal "felons_datestamp", Felon.current_index_name
12
- ensure
13
- Felon.elastic_index.delete("felons_datestamp")
14
- end
15
- end
16
- end