stretchy-model 0.6.0 → 0.6.5
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/containers/Dockerfile.opensearch +4 -3
- data/docker-compose.yml +32 -19
- data/lib/elasticsearch/api/actions/machine_learning/models/delete_model.rb +33 -0
- data/lib/elasticsearch/api/actions/machine_learning/models/deploy.rb +31 -0
- data/lib/elasticsearch/api/actions/machine_learning/models/get_model.rb +43 -0
- data/lib/elasticsearch/api/actions/machine_learning/models/get_status.rb +31 -0
- data/lib/elasticsearch/api/actions/machine_learning/models/params_registry.rb +45 -0
- data/lib/elasticsearch/api/actions/machine_learning/models/register.rb +45 -0
- data/lib/elasticsearch/api/actions/machine_learning/models/undeploy.rb +32 -0
- data/lib/elasticsearch/api/actions/machine_learning/models/update_model.rb +39 -0
- data/lib/elasticsearch/api/namespace/machine_learning/model.rb +27 -0
- data/lib/opensearch/api/actions/machine_learning/models/delete_model.rb +33 -0
- data/lib/opensearch/api/actions/machine_learning/models/deploy.rb +31 -0
- data/lib/opensearch/api/actions/machine_learning/models/get_model.rb +44 -0
- data/lib/opensearch/api/actions/machine_learning/models/get_status.rb +31 -0
- data/lib/opensearch/api/actions/machine_learning/models/params_registry.rb +45 -0
- data/lib/opensearch/api/actions/machine_learning/models/register.rb +45 -0
- data/lib/opensearch/api/actions/machine_learning/models/undeploy.rb +31 -0
- data/lib/opensearch/api/actions/machine_learning/models/update_model.rb +39 -0
- data/lib/opensearch/api/namespace/machine_learning/model.rb +27 -0
- data/lib/stretchy/attributes/type/date_time.rb +50 -0
- data/lib/stretchy/attributes/type/rank_features.rb +11 -1
- data/lib/stretchy/attributes.rb +1 -0
- data/lib/stretchy/common.rb +5 -0
- data/lib/stretchy/delegation/gateway_delegation.rb +8 -2
- data/lib/stretchy/machine_learning/model.rb +192 -0
- data/lib/stretchy/open_search_compatibility.rb +4 -0
- data/lib/stretchy/pipeline.rb +123 -0
- data/lib/stretchy/pipelines/processor.rb +55 -0
- data/lib/stretchy/querying.rb +1 -0
- data/lib/stretchy/rails/instrumentation/publishers.rb +31 -0
- data/lib/{rails → stretchy/rails}/instrumentation/railtie.rb +11 -6
- data/lib/stretchy/relation.rb +1 -0
- data/lib/stretchy/relations/query_builder.rb +73 -3
- data/lib/stretchy/relations/query_methods.rb +32 -0
- data/lib/stretchy/shared_scopes.rb +6 -1
- data/lib/stretchy/version.rb +1 -1
- data/lib/stretchy.rb +7 -2
- metadata +40 -5
- data/lib/rails/instrumentation/publishers.rb +0 -29
@@ -3,17 +3,21 @@ module Stretchy
|
|
3
3
|
|
4
4
|
class Railtie < ::Rails::Railtie
|
5
5
|
|
6
|
-
|
7
|
-
Stretchy.instrument!
|
6
|
+
require_relative 'publishers'
|
8
7
|
|
9
8
|
ActiveSupport::Notifications.subscribe 'search.stretchy' do |name, start, finish, id, payload|
|
10
9
|
message = [
|
11
|
-
|
12
|
-
|
13
|
-
|
10
|
+
Rainbow(" #{payload[:klass]}").bright,
|
11
|
+
"(#{(finish.to_time - start.to_time).round(2)}ms)",
|
12
|
+
Stretchy::Utils.to_curl(payload[:klass].constantize, payload[:search])
|
14
13
|
].join(" ")
|
15
14
|
::Rails.logger.debug(Rainbow(message).color(:yellow))
|
16
|
-
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
initializer 'stretchy.instrumentation' do
|
19
|
+
Stretchy.instrument!
|
20
|
+
end
|
17
21
|
|
18
22
|
# initializer 'stretchy.set_defaults' do
|
19
23
|
# config.elasticsearch_cache_store = :redis_store
|
@@ -21,5 +25,6 @@ module Stretchy
|
|
21
25
|
# end
|
22
26
|
|
23
27
|
end
|
28
|
+
|
24
29
|
end
|
25
30
|
end
|
data/lib/stretchy/relation.rb
CHANGED
@@ -31,6 +31,18 @@ module Stretchy
|
|
31
31
|
@query_string ||= compact_where(values[:query_string], bool: false)
|
32
32
|
end
|
33
33
|
|
34
|
+
def neural_sparse
|
35
|
+
@neural_sparse ||= values[:neural_sparse]
|
36
|
+
end
|
37
|
+
|
38
|
+
def neural
|
39
|
+
@neural ||= values[:neural]
|
40
|
+
end
|
41
|
+
|
42
|
+
def hybrid
|
43
|
+
@hybrid ||= values[:hybrid]
|
44
|
+
end
|
45
|
+
|
34
46
|
def must_nots
|
35
47
|
@must_nots ||= compact_where(values[:must_not])
|
36
48
|
end
|
@@ -104,9 +116,68 @@ module Stretchy
|
|
104
116
|
query_filters.nil? && or_filters.nil?
|
105
117
|
end
|
106
118
|
|
119
|
+
def missing_neural?
|
120
|
+
neural_sparse.nil? && neural.nil? && hybrid.nil?
|
121
|
+
end
|
122
|
+
|
123
|
+
def no_query?
|
124
|
+
missing_bool_query? && missing_query_string? && missing_query_filter? && missing_neural?
|
125
|
+
end
|
126
|
+
|
107
127
|
def build_query
|
108
|
-
return if
|
128
|
+
return if no_query?
|
109
129
|
structure.query do
|
130
|
+
|
131
|
+
structure.hybrid do
|
132
|
+
structure.queries do
|
133
|
+
hybrid[:neural].each do |n|
|
134
|
+
structure.child! do
|
135
|
+
params = n.dup
|
136
|
+
field_name, query_text = params.shift
|
137
|
+
structure.neural do
|
138
|
+
structure.set! field_name do
|
139
|
+
structure.query_text query_text
|
140
|
+
structure.extract! params, *params.keys
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
hybrid[:query].each do |query|
|
147
|
+
structure.child! do
|
148
|
+
structure.extract! query, *query.keys
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
end
|
153
|
+
end unless hybrid.nil?
|
154
|
+
|
155
|
+
structure.neural_sparse do
|
156
|
+
neural_sparse.each do |args|
|
157
|
+
params = args.dup
|
158
|
+
field_name, query_text = params.shift
|
159
|
+
structure.set! field_name do
|
160
|
+
structure.query_text query_text
|
161
|
+
structure.extract! params, *params.keys
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end unless neural_sparse.blank?
|
165
|
+
|
166
|
+
structure.neural do
|
167
|
+
neural.each do |args|
|
168
|
+
params = args.dup
|
169
|
+
field_name, query = params.shift
|
170
|
+
structure.set! field_name do
|
171
|
+
if query.is_a?(Hash)
|
172
|
+
structure.extract! query, *query.keys
|
173
|
+
else
|
174
|
+
structure.query_text query
|
175
|
+
end
|
176
|
+
structure.extract! params, *params.keys
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end unless neural.blank?
|
180
|
+
|
110
181
|
structure.regexp do
|
111
182
|
build_regexp unless regexes.nil?
|
112
183
|
end
|
@@ -121,12 +192,11 @@ module Stretchy
|
|
121
192
|
|
122
193
|
end unless missing_bool_query? && missing_query_filter?
|
123
194
|
|
124
|
-
|
125
|
-
|
126
195
|
structure.query_string do
|
127
196
|
structure.extract! query_string_options, *query_string_options.keys
|
128
197
|
structure.query query_strings
|
129
198
|
end unless query_strings.nil?
|
199
|
+
|
130
200
|
end.with_indifferent_access
|
131
201
|
end
|
132
202
|
|
@@ -19,6 +19,9 @@ module Stretchy
|
|
19
19
|
:or_filter,
|
20
20
|
:extending,
|
21
21
|
:skip_callbacks,
|
22
|
+
:neural_sparse,
|
23
|
+
:neural,
|
24
|
+
:hybrid,
|
22
25
|
:regexp
|
23
26
|
]
|
24
27
|
|
@@ -231,6 +234,35 @@ module Stretchy
|
|
231
234
|
# @see #where
|
232
235
|
alias :must :where
|
233
236
|
|
237
|
+
|
238
|
+
concerning :Neural do
|
239
|
+
def neural_sparse(opts)
|
240
|
+
spawn.neural_sparse!(opts)
|
241
|
+
end
|
242
|
+
|
243
|
+
def neural_sparse!(opts) # :nodoc:
|
244
|
+
self.neural_sparse_values += [opts]
|
245
|
+
self
|
246
|
+
end
|
247
|
+
|
248
|
+
def neural(opts)
|
249
|
+
spawn.neural!(opts)
|
250
|
+
end
|
251
|
+
|
252
|
+
def neural!(opts) # :nodoc:
|
253
|
+
self.neural_values += [opts]
|
254
|
+
self
|
255
|
+
end
|
256
|
+
|
257
|
+
def hybrid(opts)
|
258
|
+
spawn.hybrid!(opts)
|
259
|
+
end
|
260
|
+
|
261
|
+
def hybrid!(opts) # :nodoc:
|
262
|
+
self.hybrid_values += [opts]
|
263
|
+
self
|
264
|
+
end
|
265
|
+
end
|
234
266
|
# Adds a regexp condition to the query.
|
235
267
|
#
|
236
268
|
# @param field [Hash] the field to filter by and the Regexp to match
|
@@ -4,7 +4,12 @@ module Stretchy
|
|
4
4
|
|
5
5
|
included do
|
6
6
|
|
7
|
-
scope :between, ->(range, range_field = "created_at")
|
7
|
+
scope :between, ->(range, range_field = "created_at") do
|
8
|
+
range_options = {gte: range.begin}
|
9
|
+
upper_bound = range.exclude_end? ? :lt : :lte
|
10
|
+
range_options[upper_bound] = range.end
|
11
|
+
filter_query(:range, range_field => range_options)
|
12
|
+
end
|
8
13
|
scope :using_time_based_indices, lambda { |range| search_options(index: time_based_indices(range)) }
|
9
14
|
|
10
15
|
end
|
data/lib/stretchy/version.rb
CHANGED
data/lib/stretchy.rb
CHANGED
@@ -9,8 +9,8 @@ require 'active_model'
|
|
9
9
|
require 'active_support/all'
|
10
10
|
|
11
11
|
require_relative "stretchy/version"
|
12
|
-
require_relative "rails/instrumentation/railtie" if defined?(Rails)
|
13
|
-
|
12
|
+
require_relative "stretchy/rails/instrumentation/railtie" if defined?(Rails)
|
13
|
+
require_relative 'elasticsearch/api/namespace/machine_learning/model'
|
14
14
|
|
15
15
|
module Stretchy
|
16
16
|
|
@@ -27,6 +27,7 @@ module Stretchy
|
|
27
27
|
|
28
28
|
def self.boot!
|
29
29
|
loader.setup
|
30
|
+
Elasticsearch::API.send(:include, Elasticsearch::API::MachineLearning::Models)
|
30
31
|
Stretchy::Attributes.register!
|
31
32
|
end
|
32
33
|
|
@@ -53,6 +54,10 @@ module Stretchy
|
|
53
54
|
self.opensearch = true if @client.class.name =~ /OpenSearch/
|
54
55
|
end
|
55
56
|
|
57
|
+
def search_backend_const
|
58
|
+
@opensearch ? OpenSearch : Elasticsearch
|
59
|
+
end
|
60
|
+
|
56
61
|
def opensearch=(bool)
|
57
62
|
@opensearch = bool
|
58
63
|
OpenSearchCompatibility.opensearch_patch! if bool
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stretchy-model
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Spencer Markowski
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-03-
|
11
|
+
date: 2024-03-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: zeitwerk
|
@@ -206,6 +206,20 @@ dependencies:
|
|
206
206
|
- - "~>"
|
207
207
|
- !ruby/object:Gem::Version
|
208
208
|
version: 0.5.0
|
209
|
+
- !ruby/object:Gem::Dependency
|
210
|
+
name: faker
|
211
|
+
requirement: !ruby/object:Gem::Requirement
|
212
|
+
requirements:
|
213
|
+
- - "~>"
|
214
|
+
- !ruby/object:Gem::Version
|
215
|
+
version: '2.18'
|
216
|
+
type: :development
|
217
|
+
prerelease: false
|
218
|
+
version_requirements: !ruby/object:Gem::Requirement
|
219
|
+
requirements:
|
220
|
+
- - "~>"
|
221
|
+
- !ruby/object:Gem::Version
|
222
|
+
version: '2.18'
|
209
223
|
description: Provides a familiar ActiveRecord-like interface for working with Elasticsearch
|
210
224
|
email:
|
211
225
|
- spencer.markowski@theablefew.com
|
@@ -224,8 +238,24 @@ files:
|
|
224
238
|
- containers/Dockerfile.elasticsearch
|
225
239
|
- containers/Dockerfile.opensearch
|
226
240
|
- docker-compose.yml
|
227
|
-
- lib/
|
228
|
-
- lib/
|
241
|
+
- lib/elasticsearch/api/actions/machine_learning/models/delete_model.rb
|
242
|
+
- lib/elasticsearch/api/actions/machine_learning/models/deploy.rb
|
243
|
+
- lib/elasticsearch/api/actions/machine_learning/models/get_model.rb
|
244
|
+
- lib/elasticsearch/api/actions/machine_learning/models/get_status.rb
|
245
|
+
- lib/elasticsearch/api/actions/machine_learning/models/params_registry.rb
|
246
|
+
- lib/elasticsearch/api/actions/machine_learning/models/register.rb
|
247
|
+
- lib/elasticsearch/api/actions/machine_learning/models/undeploy.rb
|
248
|
+
- lib/elasticsearch/api/actions/machine_learning/models/update_model.rb
|
249
|
+
- lib/elasticsearch/api/namespace/machine_learning/model.rb
|
250
|
+
- lib/opensearch/api/actions/machine_learning/models/delete_model.rb
|
251
|
+
- lib/opensearch/api/actions/machine_learning/models/deploy.rb
|
252
|
+
- lib/opensearch/api/actions/machine_learning/models/get_model.rb
|
253
|
+
- lib/opensearch/api/actions/machine_learning/models/get_status.rb
|
254
|
+
- lib/opensearch/api/actions/machine_learning/models/params_registry.rb
|
255
|
+
- lib/opensearch/api/actions/machine_learning/models/register.rb
|
256
|
+
- lib/opensearch/api/actions/machine_learning/models/undeploy.rb
|
257
|
+
- lib/opensearch/api/actions/machine_learning/models/update_model.rb
|
258
|
+
- lib/opensearch/api/namespace/machine_learning/model.rb
|
229
259
|
- lib/stretchy.rb
|
230
260
|
- lib/stretchy/associations.rb
|
231
261
|
- lib/stretchy/associations/associated_validator.rb
|
@@ -283,12 +313,17 @@ files:
|
|
283
313
|
- lib/stretchy/delegation/delegate_cache.rb
|
284
314
|
- lib/stretchy/delegation/gateway_delegation.rb
|
285
315
|
- lib/stretchy/indexing/bulk.rb
|
316
|
+
- lib/stretchy/machine_learning/model.rb
|
286
317
|
- lib/stretchy/model/callbacks.rb
|
287
318
|
- lib/stretchy/model/serialization.rb
|
288
319
|
- lib/stretchy/null_relation.rb
|
289
320
|
- lib/stretchy/open_search_compatibility.rb
|
290
321
|
- lib/stretchy/persistence.rb
|
322
|
+
- lib/stretchy/pipeline.rb
|
323
|
+
- lib/stretchy/pipelines/processor.rb
|
291
324
|
- lib/stretchy/querying.rb
|
325
|
+
- lib/stretchy/rails/instrumentation/publishers.rb
|
326
|
+
- lib/stretchy/rails/instrumentation/railtie.rb
|
292
327
|
- lib/stretchy/record.rb
|
293
328
|
- lib/stretchy/refreshable.rb
|
294
329
|
- lib/stretchy/relation.rb
|
@@ -334,7 +369,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
334
369
|
- !ruby/object:Gem::Version
|
335
370
|
version: '0'
|
336
371
|
requirements: []
|
337
|
-
rubygems_version: 3.
|
372
|
+
rubygems_version: 3.3.7
|
338
373
|
signing_key:
|
339
374
|
specification_version: 4
|
340
375
|
summary: Rails ORM for Elasticsearch
|
@@ -1,29 +0,0 @@
|
|
1
|
-
module Rails
|
2
|
-
module Instrumentation
|
3
|
-
module Publishers
|
4
|
-
|
5
|
-
module Record
|
6
|
-
|
7
|
-
extend ActiveSupport::Concern
|
8
|
-
|
9
|
-
included do
|
10
|
-
unless method_defined?(:search_without_instrumentation!)
|
11
|
-
alias_method :search_without_instrumentation!, :search
|
12
|
-
alias_method :search, :search_with_instrumentation!
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
def search_with_instrumentation!(query_or_definition, options={})
|
17
|
-
ActiveSupport::Notifications.instrument "search.stretchy",
|
18
|
-
name: "Search",
|
19
|
-
klass: self.base_class.to_s,
|
20
|
-
search: {index: self.index_name, body: query_or_definition }.merge(options) do
|
21
|
-
search_without_instrumentation!(query_or_definition, options)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
end
|
26
|
-
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|