caoutsearch 0.0.1 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +816 -7
  3. data/lib/caoutsearch/config/mappings.rb +1 -1
  4. data/lib/caoutsearch/filter/base.rb +11 -7
  5. data/lib/caoutsearch/filter/boolean.rb +1 -1
  6. data/lib/caoutsearch/filter/date.rb +93 -22
  7. data/lib/caoutsearch/filter/default.rb +10 -10
  8. data/lib/caoutsearch/filter/geo_point.rb +1 -1
  9. data/lib/caoutsearch/filter/match.rb +5 -5
  10. data/lib/caoutsearch/filter/none.rb +1 -1
  11. data/lib/caoutsearch/filter/range.rb +6 -6
  12. data/lib/caoutsearch/index/document.rb +11 -11
  13. data/lib/caoutsearch/index/indice_versions.rb +3 -3
  14. data/lib/caoutsearch/index/internal_dsl.rb +3 -3
  15. data/lib/caoutsearch/index/reindex.rb +11 -11
  16. data/lib/caoutsearch/index/scoping.rb +3 -3
  17. data/lib/caoutsearch/index/serialization.rb +13 -13
  18. data/lib/caoutsearch/instrumentation/base.rb +12 -12
  19. data/lib/caoutsearch/instrumentation/search.rb +11 -2
  20. data/lib/caoutsearch/mappings.rb +1 -1
  21. data/lib/caoutsearch/model/indexable.rb +57 -0
  22. data/lib/caoutsearch/model/searchable.rb +31 -0
  23. data/lib/caoutsearch/model.rb +12 -0
  24. data/lib/caoutsearch/response/aggregations.rb +50 -0
  25. data/lib/caoutsearch/response/response.rb +9 -0
  26. data/lib/caoutsearch/response/suggestions.rb +9 -0
  27. data/lib/caoutsearch/response.rb +6 -0
  28. data/lib/caoutsearch/search/adapter/active_record.rb +39 -0
  29. data/lib/caoutsearch/search/base.rb +16 -15
  30. data/lib/caoutsearch/search/batch/scroll.rb +93 -0
  31. data/lib/caoutsearch/search/batch/search_after.rb +71 -0
  32. data/lib/caoutsearch/search/batch_methods.rb +63 -0
  33. data/lib/caoutsearch/search/callbacks.rb +28 -0
  34. data/lib/caoutsearch/search/delete_methods.rb +19 -0
  35. data/lib/caoutsearch/search/dsl/item.rb +2 -2
  36. data/lib/caoutsearch/search/inspect.rb +34 -0
  37. data/lib/caoutsearch/search/instrumentation.rb +19 -0
  38. data/lib/caoutsearch/search/internal_dsl.rb +107 -0
  39. data/lib/caoutsearch/search/naming.rb +45 -0
  40. data/lib/caoutsearch/search/point_in_time.rb +28 -0
  41. data/lib/caoutsearch/search/query/boolean.rb +4 -4
  42. data/lib/caoutsearch/search/query/nested.rb +1 -1
  43. data/lib/caoutsearch/search/query/setters.rb +4 -4
  44. data/lib/caoutsearch/search/query_builder/aggregations.rb +49 -0
  45. data/lib/caoutsearch/search/query_builder.rb +89 -0
  46. data/lib/caoutsearch/search/query_methods.rb +157 -0
  47. data/lib/caoutsearch/search/records.rb +23 -0
  48. data/lib/caoutsearch/search/resettable.rb +38 -0
  49. data/lib/caoutsearch/search/response.rb +97 -0
  50. data/lib/caoutsearch/search/sanitizer.rb +2 -2
  51. data/lib/caoutsearch/search/search_methods.rb +239 -0
  52. data/lib/caoutsearch/search/type_cast.rb +14 -6
  53. data/lib/caoutsearch/search/value.rb +10 -10
  54. data/lib/caoutsearch/search/value_overflow.rb +1 -1
  55. data/lib/caoutsearch/settings.rb +1 -1
  56. data/lib/caoutsearch/testing/mock_requests.rb +105 -0
  57. data/lib/caoutsearch/testing.rb +3 -0
  58. data/lib/caoutsearch/version.rb +1 -1
  59. data/lib/caoutsearch.rb +10 -5
  60. metadata +45 -127
  61. data/lib/caoutsearch/search/search/delete_methods.rb +0 -21
  62. data/lib/caoutsearch/search/search/inspect.rb +0 -36
  63. data/lib/caoutsearch/search/search/instrumentation.rb +0 -21
  64. data/lib/caoutsearch/search/search/internal_dsl.rb +0 -77
  65. data/lib/caoutsearch/search/search/naming.rb +0 -47
  66. data/lib/caoutsearch/search/search/query_builder.rb +0 -94
  67. data/lib/caoutsearch/search/search/query_methods.rb +0 -180
  68. data/lib/caoutsearch/search/search/resettable.rb +0 -35
  69. data/lib/caoutsearch/search/search/response.rb +0 -88
  70. data/lib/caoutsearch/search/search/scroll_methods.rb +0 -113
  71. data/lib/caoutsearch/search/search/search_methods.rb +0 -230
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: caoutsearch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Savater Sebastien
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2022-09-26 00:00:00.000000000 Z
12
+ date: 2023-01-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -40,145 +40,47 @@ dependencies:
40
40
  - !ruby/object:Gem::Version
41
41
  version: 8.x
42
42
  - !ruby/object:Gem::Dependency
43
- name: zeitwerk
43
+ name: hashie
44
44
  requirement: !ruby/object:Gem::Requirement
45
45
  requirements:
46
46
  - - "~>"
47
47
  - !ruby/object:Gem::Version
48
- version: 2.6.0
48
+ version: '5.0'
49
49
  type: :runtime
50
50
  prerelease: false
51
51
  version_requirements: !ruby/object:Gem::Requirement
52
52
  requirements:
53
53
  - - "~>"
54
54
  - !ruby/object:Gem::Version
55
- version: 2.6.0
56
- - !ruby/object:Gem::Dependency
57
- name: bundler
58
- requirement: !ruby/object:Gem::Requirement
59
- requirements:
60
- - - ">="
61
- - !ruby/object:Gem::Version
62
- version: '0'
63
- type: :development
64
- prerelease: false
65
- version_requirements: !ruby/object:Gem::Requirement
66
- requirements:
67
- - - ">="
68
- - !ruby/object:Gem::Version
69
- version: '0'
70
- - !ruby/object:Gem::Dependency
71
- name: gem-release
72
- requirement: !ruby/object:Gem::Requirement
73
- requirements:
74
- - - ">="
75
- - !ruby/object:Gem::Version
76
- version: '0'
77
- type: :development
78
- prerelease: false
79
- version_requirements: !ruby/object:Gem::Requirement
80
- requirements:
81
- - - ">="
82
- - !ruby/object:Gem::Version
83
- version: '0'
84
- - !ruby/object:Gem::Dependency
85
- name: rake
86
- requirement: !ruby/object:Gem::Requirement
87
- requirements:
88
- - - ">="
89
- - !ruby/object:Gem::Version
90
- version: '0'
91
- type: :development
92
- prerelease: false
93
- version_requirements: !ruby/object:Gem::Requirement
94
- requirements:
95
- - - ">="
96
- - !ruby/object:Gem::Version
97
- version: '0'
98
- - !ruby/object:Gem::Dependency
99
- name: rspec
100
- requirement: !ruby/object:Gem::Requirement
101
- requirements:
102
- - - ">="
103
- - !ruby/object:Gem::Version
104
- version: '0'
105
- type: :development
106
- prerelease: false
107
- version_requirements: !ruby/object:Gem::Requirement
108
- requirements:
109
- - - ">="
110
- - !ruby/object:Gem::Version
111
- version: '0'
112
- - !ruby/object:Gem::Dependency
113
- name: rubocop
114
- requirement: !ruby/object:Gem::Requirement
115
- requirements:
116
- - - ">="
117
- - !ruby/object:Gem::Version
118
- version: '0'
119
- type: :development
120
- prerelease: false
121
- version_requirements: !ruby/object:Gem::Requirement
122
- requirements:
123
- - - ">="
124
- - !ruby/object:Gem::Version
125
- version: '0'
126
- - !ruby/object:Gem::Dependency
127
- name: rubocop-rake
128
- requirement: !ruby/object:Gem::Requirement
129
- requirements:
130
- - - ">="
131
- - !ruby/object:Gem::Version
132
- version: '0'
133
- type: :development
134
- prerelease: false
135
- version_requirements: !ruby/object:Gem::Requirement
136
- requirements:
137
- - - ">="
138
- - !ruby/object:Gem::Version
139
- version: '0'
140
- - !ruby/object:Gem::Dependency
141
- name: rubocop-rspec
142
- requirement: !ruby/object:Gem::Requirement
143
- requirements:
144
- - - ">="
145
- - !ruby/object:Gem::Version
146
- version: '0'
147
- type: :development
148
- prerelease: false
149
- version_requirements: !ruby/object:Gem::Requirement
150
- requirements:
151
- - - ">="
152
- - !ruby/object:Gem::Version
153
- version: '0'
55
+ version: '5.0'
154
56
  - !ruby/object:Gem::Dependency
155
- name: rubocop-performance
57
+ name: multi_json
156
58
  requirement: !ruby/object:Gem::Requirement
157
59
  requirements:
158
- - - ">="
60
+ - - "~>"
159
61
  - !ruby/object:Gem::Version
160
- version: '0'
161
- type: :development
62
+ version: '1.15'
63
+ type: :runtime
162
64
  prerelease: false
163
65
  version_requirements: !ruby/object:Gem::Requirement
164
66
  requirements:
165
- - - ">="
67
+ - - "~>"
166
68
  - !ruby/object:Gem::Version
167
- version: '0'
69
+ version: '1.15'
168
70
  - !ruby/object:Gem::Dependency
169
- name: standard
71
+ name: zeitwerk
170
72
  requirement: !ruby/object:Gem::Requirement
171
73
  requirements:
172
- - - ">="
74
+ - - "~>"
173
75
  - !ruby/object:Gem::Version
174
- version: '0'
175
- type: :development
76
+ version: '2.6'
77
+ type: :runtime
176
78
  prerelease: false
177
79
  version_requirements: !ruby/object:Gem::Requirement
178
80
  requirements:
179
- - - ">="
81
+ - - "~>"
180
82
  - !ruby/object:Gem::Version
181
- version: '0'
83
+ version: '2.6'
182
84
  description:
183
85
  email: github.60k5k@simplelogin.co
184
86
  executables: []
@@ -215,9 +117,27 @@ files:
215
117
  - lib/caoutsearch/instrumentation/index.rb
216
118
  - lib/caoutsearch/instrumentation/search.rb
217
119
  - lib/caoutsearch/mappings.rb
120
+ - lib/caoutsearch/model.rb
121
+ - lib/caoutsearch/model/indexable.rb
122
+ - lib/caoutsearch/model/searchable.rb
123
+ - lib/caoutsearch/response.rb
124
+ - lib/caoutsearch/response/aggregations.rb
125
+ - lib/caoutsearch/response/response.rb
126
+ - lib/caoutsearch/response/suggestions.rb
218
127
  - lib/caoutsearch/search.rb
128
+ - lib/caoutsearch/search/adapter/active_record.rb
219
129
  - lib/caoutsearch/search/base.rb
130
+ - lib/caoutsearch/search/batch/scroll.rb
131
+ - lib/caoutsearch/search/batch/search_after.rb
132
+ - lib/caoutsearch/search/batch_methods.rb
133
+ - lib/caoutsearch/search/callbacks.rb
134
+ - lib/caoutsearch/search/delete_methods.rb
220
135
  - lib/caoutsearch/search/dsl/item.rb
136
+ - lib/caoutsearch/search/inspect.rb
137
+ - lib/caoutsearch/search/instrumentation.rb
138
+ - lib/caoutsearch/search/internal_dsl.rb
139
+ - lib/caoutsearch/search/naming.rb
140
+ - lib/caoutsearch/search/point_in_time.rb
221
141
  - lib/caoutsearch/search/query/base.rb
222
142
  - lib/caoutsearch/search/query/boolean.rb
223
143
  - lib/caoutsearch/search/query/cleaning.rb
@@ -225,22 +145,20 @@ files:
225
145
  - lib/caoutsearch/search/query/merge.rb
226
146
  - lib/caoutsearch/search/query/nested.rb
227
147
  - lib/caoutsearch/search/query/setters.rb
148
+ - lib/caoutsearch/search/query_builder.rb
149
+ - lib/caoutsearch/search/query_builder/aggregations.rb
150
+ - lib/caoutsearch/search/query_methods.rb
151
+ - lib/caoutsearch/search/records.rb
152
+ - lib/caoutsearch/search/resettable.rb
153
+ - lib/caoutsearch/search/response.rb
228
154
  - lib/caoutsearch/search/sanitizer.rb
229
- - lib/caoutsearch/search/search/delete_methods.rb
230
- - lib/caoutsearch/search/search/inspect.rb
231
- - lib/caoutsearch/search/search/instrumentation.rb
232
- - lib/caoutsearch/search/search/internal_dsl.rb
233
- - lib/caoutsearch/search/search/naming.rb
234
- - lib/caoutsearch/search/search/query_builder.rb
235
- - lib/caoutsearch/search/search/query_methods.rb
236
- - lib/caoutsearch/search/search/resettable.rb
237
- - lib/caoutsearch/search/search/response.rb
238
- - lib/caoutsearch/search/search/scroll_methods.rb
239
- - lib/caoutsearch/search/search/search_methods.rb
155
+ - lib/caoutsearch/search/search_methods.rb
240
156
  - lib/caoutsearch/search/type_cast.rb
241
157
  - lib/caoutsearch/search/value.rb
242
158
  - lib/caoutsearch/search/value_overflow.rb
243
159
  - lib/caoutsearch/settings.rb
160
+ - lib/caoutsearch/testing.rb
161
+ - lib/caoutsearch/testing/mock_requests.rb
244
162
  - lib/caoutsearch/version.rb
245
163
  homepage: http://github.com/mon-territoire/caoutsearch
246
164
  licenses:
@@ -261,7 +179,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
261
179
  - !ruby/object:Gem::Version
262
180
  version: '0'
263
181
  requirements: []
264
- rubygems_version: 3.3.7
182
+ rubygems_version: 3.1.6
265
183
  signing_key:
266
184
  specification_version: 4
267
185
  summary: An alternative approach to index & search with Elasticsearch & Ruby on Rails
@@ -1,21 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Caoutsearch
4
- module Search
5
- module Search
6
- module DeleteMethods
7
- def delete_documents
8
- request_payload = {
9
- index: index_name,
10
- body: build.to_h
11
- }
12
-
13
- instrument(:delete) do |event_payload|
14
- event_payload[:request] = request_payload
15
- event_payload[:response] = client.delete_by_query(request_payload)
16
- end
17
- end
18
- end
19
- end
20
- end
21
- end
@@ -1,36 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Caoutsearch
4
- module Search
5
- module Search
6
- module Inspect
7
- PROPERTIES_TO_INSPECT = %i[
8
- search_criteria
9
- current_context
10
- current_order
11
- current_page
12
- current_limit
13
- current_offset
14
- current_aggregations
15
- current_suggestions
16
- current_returns
17
- ].freeze
18
-
19
- def inspect
20
- properties = properties_to_inspect.map { |k, v| " #{k}: #{v}" }
21
-
22
- "#<#{self.class}#{properties.join(",")}>"
23
- end
24
-
25
- private
26
-
27
- def properties_to_inspect
28
- PROPERTIES_TO_INSPECT.each_with_object({}) do |name, properties|
29
- value = instance_variable_get("@#{name}")
30
- properties[name] = value.inspect if value
31
- end
32
- end
33
- end
34
- end
35
- end
36
- end
@@ -1,21 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Caoutsearch
4
- module Search
5
- module Search
6
- module Instrumentation
7
- extend ActiveSupport::Concern
8
-
9
- def instrument(action, **options, &block)
10
- ActiveSupport::Notifications.instrument("#{action}.caoutsearch_search", **options, klass: self.class.to_s, &block)
11
- end
12
-
13
- class_methods do
14
- def instrument(action, **options, &block)
15
- ActiveSupport::Notifications.instrument("#{action}.caoutsearch_search", **options, klass: to_s, &block)
16
- end
17
- end
18
- end
19
- end
20
- end
21
- end
@@ -1,77 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Caoutsearch
4
- module Search
5
- module Search
6
- module InternalDSL
7
- extend ActiveSupport::Concern
8
-
9
- included do
10
- # Do to not make:
11
- # self.config[:filter][key] = ...
12
- #
13
- # Changing only config members will lead to inheritance issue.
14
- # Instead, make:
15
- # self.config = config.deep_dup
16
- # self.config[:filter][key] = ...
17
- #
18
- class_attribute :config, default: {
19
- contexts: ActiveSupport::HashWithIndifferentAccess.new,
20
- filters: ActiveSupport::HashWithIndifferentAccess.new,
21
- defaults: ActiveSupport::HashWithIndifferentAccess.new,
22
- aggregations: ActiveSupport::HashWithIndifferentAccess.new,
23
- suggestions: ActiveSupport::HashWithIndifferentAccess.new,
24
- sorts: ActiveSupport::HashWithIndifferentAccess.new
25
- }
26
- end
27
-
28
- class_methods do
29
- def match_all(&block)
30
- self.config = config.deep_dup
31
- config[:match_all] = block
32
- end
33
-
34
- %w[context default].each do |method|
35
- config_attribute = method.pluralize.to_sym
36
-
37
- define_method method do |name = nil, &block|
38
- self.config = config.deep_dup
39
-
40
- if name
41
- config[config_attribute][name] = Caoutsearch::Search::DSL::Item.new(name, &block)
42
- else
43
- config[config_attribute][:__undef__] = block
44
- end
45
- end
46
- end
47
-
48
- %w[filter aggregation sort suggestion].each do |method|
49
- config_attribute = method.pluralize.to_sym
50
-
51
- define_method method do |name = nil, **options, &block|
52
- self.config = config.deep_dup
53
-
54
- if name
55
- config[config_attribute][name.to_s] = Caoutsearch::Search::DSL::Item.new(name, options, &block)
56
- else
57
- config[config_attribute][:__undef__] = block
58
- end
59
- end
60
- end
61
-
62
- def alias_filter(new_name, old_name)
63
- filter(new_name) { |value| search_by(old_name => value) }
64
- end
65
-
66
- def alias_sort(new_name, old_name)
67
- sort(new_name) { |direction| sort_by(old_name, direction) }
68
- end
69
-
70
- def alias_aggregation(new_name, old_name)
71
- aggregation(new_name) { aggregate_with(old_name) }
72
- end
73
- end
74
- end
75
- end
76
- end
77
- end
@@ -1,47 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Caoutsearch
4
- module Search
5
- module Search
6
- module Naming
7
- extend ActiveSupport::Concern
8
-
9
- included do
10
- delegate :model, :model_name, :index_name, to: :class
11
- end
12
-
13
- class_methods do
14
- def model
15
- @model ||= model_name.constantize
16
- end
17
-
18
- def model_name
19
- @model_name ||= defaut_model_name
20
- end
21
-
22
- def model_name=(name)
23
- @model_name = name
24
- end
25
-
26
- def index_name
27
- @index_name ||= default_index_name
28
- end
29
-
30
- def index_name=(name)
31
- @index_name = name
32
- end
33
-
34
- private
35
-
36
- def default_index_name
37
- name.gsub(/Search$/, "").tableize.tr("/", "_")
38
- end
39
-
40
- def defaut_model_name
41
- name.gsub(/Search$/, "")
42
- end
43
- end
44
- end
45
- end
46
- end
47
- end
@@ -1,94 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Caoutsearch
4
- module Search
5
- module Search
6
- module QueryBuilder
7
- extend ActiveSupport::Concern
8
-
9
- included do
10
- include ActiveSupport::Callbacks
11
- define_callbacks :build
12
- end
13
-
14
- def build
15
- run_callbacks :build do
16
- apply_prepend_hash
17
- apply_search_criteria
18
- apply_context
19
- apply_defaults
20
- apply_limits
21
- apply_orders
22
- apply_aggregations
23
- apply_suggestions
24
- apply_fields
25
- apply_source
26
- apply_total_hits_tracking
27
- apply_append_hash
28
- end
29
-
30
- elasticsearch_query.clean
31
- elasticsearch_query
32
- end
33
-
34
- def apply_search_criteria
35
- search_by(search_criteria)
36
- end
37
-
38
- def apply_context
39
- return unless current_context
40
-
41
- item = config[:contexts][current_context.to_s]
42
- instance_exec(&item.block) if item
43
- end
44
-
45
- def apply_defaults
46
- keys = search_criteria_keys.map(&:to_s)
47
-
48
- config[:defaults].each do |key, item|
49
- instance_exec(&item.block) unless keys.include?(key.to_s)
50
- end
51
- end
52
-
53
- def apply_limits
54
- elasticsearch_query[:size] = current_limit.to_i if @current_page || @current_limit
55
- elasticsearch_query[:from] = current_offset if @current_page || @current_offset
56
- end
57
-
58
- def apply_orders
59
- return if current_limit.zero?
60
-
61
- order_by(current_order || :default)
62
- end
63
-
64
- def apply_aggregations
65
- aggregate_with(*current_aggregations) if current_aggregations
66
- end
67
-
68
- def apply_suggestions
69
- suggest_with(*current_suggestions) if current_suggestions
70
- end
71
-
72
- def apply_fields
73
- elasticsearch_query[:fields] = current_fields.map(&:to_s) if current_fields
74
- end
75
-
76
- def apply_source
77
- elasticsearch_query[:_source] = current_source unless current_source.nil?
78
- end
79
-
80
- def apply_total_hits_tracking
81
- elasticsearch_query[:track_total_hits] = @track_total_hits if @track_total_hits
82
- end
83
-
84
- def apply_prepend_hash
85
- elasticsearch_query.merge!(@prepend_hash) if @prepend_hash
86
- end
87
-
88
- def apply_append_hash
89
- elasticsearch_query.merge!(@append_hash) if @append_hash
90
- end
91
- end
92
- end
93
- end
94
- end