stretchy-model 0.6.0 → 0.6.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.yardopts +2 -1
- data/README.md +28 -10
- data/Rakefile +56 -0
- data/containers/Dockerfile.opensearch +4 -3
- data/docker-compose.yml +32 -19
- data/docs/.nojekyll +0 -0
- data/docs/README.md +147 -0
- data/docs/_coverpage.md +14 -0
- data/docs/_sidebar.md +14 -0
- data/docs/examples/_sidebar.md +15 -0
- data/docs/examples/data_analysis.md +216 -0
- data/docs/examples/semantic_search_with_llm.md +83 -0
- data/docs/examples/simple-ingest-pipeline.md +326 -0
- data/docs/guides/_sidebar.md +14 -0
- data/docs/guides/aggregations.md +142 -0
- data/docs/guides/machine-learning.md +154 -0
- data/docs/guides/models.md +372 -0
- data/docs/guides/pipelines.md +151 -0
- data/docs/guides/querying.md +361 -0
- data/docs/guides/quick-start.md +72 -0
- data/docs/guides/scopes.md +125 -0
- data/docs/index.html +113 -0
- data/docs/stretchy.cover.png +0 -0
- data/docs/stretchy.logo.png +0 -0
- data/docs/styles.css +90 -0
- 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/transformers/keyword_transformer.rb +41 -35
- data/lib/stretchy/attributes/type/array.rb +24 -1
- data/lib/stretchy/attributes/type/base.rb +6 -2
- data/lib/stretchy/attributes/type/binary.rb +24 -17
- data/lib/stretchy/attributes/type/boolean.rb +29 -22
- data/lib/stretchy/attributes/type/completion.rb +18 -10
- data/lib/stretchy/attributes/type/constant_keyword.rb +35 -26
- data/lib/stretchy/attributes/type/date_time.rb +81 -20
- data/lib/stretchy/attributes/type/dense_vector.rb +46 -49
- data/lib/stretchy/attributes/type/flattened.rb +28 -19
- data/lib/stretchy/attributes/type/geo_point.rb +21 -12
- data/lib/stretchy/attributes/type/geo_shape.rb +21 -12
- data/lib/stretchy/attributes/type/hash.rb +24 -10
- data/lib/stretchy/attributes/type/histogram.rb +25 -0
- data/lib/stretchy/attributes/type/ip.rb +26 -17
- data/lib/stretchy/attributes/type/join.rb +16 -7
- data/lib/stretchy/attributes/type/keyword.rb +21 -26
- data/lib/stretchy/attributes/type/knn_vector.rb +47 -0
- data/lib/stretchy/attributes/type/match_only_text.rb +22 -1
- data/lib/stretchy/attributes/type/nested.rb +16 -11
- data/lib/stretchy/attributes/type/numeric/base.rb +30 -22
- data/lib/stretchy/attributes/type/numeric/byte.rb +20 -0
- data/lib/stretchy/attributes/type/numeric/double.rb +20 -0
- data/lib/stretchy/attributes/type/numeric/float.rb +20 -0
- data/lib/stretchy/attributes/type/numeric/half_float.rb +20 -0
- data/lib/stretchy/attributes/type/numeric/integer.rb +21 -1
- data/lib/stretchy/attributes/type/numeric/long.rb +20 -0
- data/lib/stretchy/attributes/type/numeric/scaled_float.rb +16 -7
- data/lib/stretchy/attributes/type/numeric/short.rb +20 -0
- data/lib/stretchy/attributes/type/numeric/unsigned_long.rb +21 -1
- data/lib/stretchy/attributes/type/percolator.rb +16 -4
- data/lib/stretchy/attributes/type/point.rb +19 -9
- data/lib/stretchy/attributes/type/range/base.rb +24 -1
- data/lib/stretchy/attributes/type/range/date_range.rb +21 -5
- data/lib/stretchy/attributes/type/range/double_range.rb +20 -4
- data/lib/stretchy/attributes/type/range/float_range.rb +21 -5
- data/lib/stretchy/attributes/type/range/integer_range.rb +20 -4
- data/lib/stretchy/attributes/type/range/ip_range.rb +20 -4
- data/lib/stretchy/attributes/type/range/long_range.rb +20 -4
- data/lib/stretchy/attributes/type/rank_feature.rb +16 -6
- data/lib/stretchy/attributes/type/rank_features.rb +27 -10
- data/lib/stretchy/attributes/type/search_as_you_type.rb +28 -18
- data/lib/stretchy/attributes/type/shape.rb +19 -9
- data/lib/stretchy/attributes/type/sparse_vector.rb +25 -21
- data/lib/stretchy/attributes/type/string.rb +42 -1
- data/lib/stretchy/attributes/type/text.rb +53 -28
- data/lib/stretchy/attributes/type/token_count.rb +21 -11
- data/lib/stretchy/attributes/type/version.rb +16 -6
- data/lib/stretchy/attributes/type/wildcard.rb +36 -25
- data/lib/stretchy/attributes.rb +30 -0
- data/lib/stretchy/delegation/gateway_delegation.rb +86 -2
- data/lib/stretchy/index_setting.rb +94 -0
- data/lib/stretchy/indexing/bulk.rb +75 -3
- data/lib/stretchy/machine_learning/model.rb +192 -0
- data/lib/stretchy/model/callbacks.rb +1 -0
- data/lib/stretchy/model/common.rb +157 -0
- data/lib/stretchy/model/persistence.rb +144 -0
- data/lib/stretchy/model/refreshable.rb +26 -0
- data/lib/stretchy/open_search_compatibility.rb +4 -0
- data/lib/stretchy/pipeline.rb +124 -0
- data/lib/stretchy/pipelines/processor.rb +57 -0
- data/lib/stretchy/querying.rb +7 -7
- data/lib/stretchy/rails/instrumentation/publishers.rb +31 -0
- data/lib/{rails → stretchy/rails}/instrumentation/railtie.rb +11 -6
- data/lib/stretchy/record.rb +5 -4
- data/lib/stretchy/relation.rb +230 -28
- data/lib/stretchy/relations/aggregation_methods/aggregation.rb +59 -0
- data/lib/stretchy/relations/aggregation_methods/avg.rb +45 -0
- data/lib/stretchy/relations/aggregation_methods/bucket_script.rb +47 -0
- data/lib/stretchy/relations/aggregation_methods/bucket_selector.rb +47 -0
- data/lib/stretchy/relations/aggregation_methods/bucket_sort.rb +47 -0
- data/lib/stretchy/relations/aggregation_methods/cardinality.rb +47 -0
- data/lib/stretchy/relations/aggregation_methods/children.rb +47 -0
- data/lib/stretchy/relations/aggregation_methods/composite.rb +41 -0
- data/lib/stretchy/relations/aggregation_methods/date_histogram.rb +53 -0
- data/lib/stretchy/relations/aggregation_methods/date_range.rb +53 -0
- data/lib/stretchy/relations/aggregation_methods/extended_stats.rb +48 -0
- data/lib/stretchy/relations/aggregation_methods/filter.rb +47 -0
- data/lib/stretchy/relations/aggregation_methods/filters.rb +47 -0
- data/lib/stretchy/relations/aggregation_methods/geo_bounds.rb +40 -0
- data/lib/stretchy/relations/aggregation_methods/geo_centroid.rb +40 -0
- data/lib/stretchy/relations/aggregation_methods/global.rb +39 -0
- data/lib/stretchy/relations/aggregation_methods/histogram.rb +43 -0
- data/lib/stretchy/relations/aggregation_methods/ip_range.rb +41 -0
- data/lib/stretchy/relations/aggregation_methods/max.rb +40 -0
- data/lib/stretchy/relations/aggregation_methods/min.rb +41 -0
- data/lib/stretchy/relations/aggregation_methods/missing.rb +40 -0
- data/lib/stretchy/relations/aggregation_methods/nested.rb +40 -0
- data/lib/stretchy/relations/aggregation_methods/percentile_ranks.rb +45 -0
- data/lib/stretchy/relations/aggregation_methods/percentiles.rb +45 -0
- data/lib/stretchy/relations/aggregation_methods/range.rb +42 -0
- data/lib/stretchy/relations/aggregation_methods/reverse_nested.rb +40 -0
- data/lib/stretchy/relations/aggregation_methods/sampler.rb +40 -0
- data/lib/stretchy/relations/aggregation_methods/scripted_metric.rb +43 -0
- data/lib/stretchy/relations/aggregation_methods/significant_terms.rb +45 -0
- data/lib/stretchy/relations/aggregation_methods/stats.rb +42 -0
- data/lib/stretchy/relations/aggregation_methods/sum.rb +42 -0
- data/lib/stretchy/relations/aggregation_methods/terms.rb +46 -0
- data/lib/stretchy/relations/aggregation_methods/top_hits.rb +42 -0
- data/lib/stretchy/relations/aggregation_methods/top_metrics.rb +44 -0
- data/lib/stretchy/relations/aggregation_methods/value_count.rb +41 -0
- data/lib/stretchy/relations/aggregation_methods/weighted_avg.rb +42 -0
- data/lib/stretchy/relations/aggregation_methods.rb +20 -749
- data/lib/stretchy/relations/finder_methods.rb +2 -18
- data/lib/stretchy/relations/null_relation.rb +55 -0
- data/lib/stretchy/relations/query_builder.rb +139 -23
- data/lib/stretchy/relations/query_methods/bind.rb +19 -0
- data/lib/stretchy/relations/query_methods/extending.rb +29 -0
- data/lib/stretchy/relations/query_methods/fields.rb +70 -0
- data/lib/stretchy/relations/query_methods/filter_query.rb +53 -0
- data/lib/stretchy/relations/query_methods/has_field.rb +40 -0
- data/lib/stretchy/relations/query_methods/highlight.rb +75 -0
- data/lib/stretchy/relations/query_methods/hybrid.rb +60 -0
- data/lib/stretchy/relations/query_methods/ids.rb +40 -0
- data/lib/stretchy/relations/query_methods/match.rb +52 -0
- data/lib/stretchy/relations/query_methods/must_not.rb +54 -0
- data/lib/stretchy/relations/query_methods/neural.rb +58 -0
- data/lib/stretchy/relations/query_methods/neural_sparse.rb +43 -0
- data/lib/stretchy/relations/query_methods/none.rb +21 -0
- data/lib/stretchy/relations/query_methods/or_filter.rb +21 -0
- data/lib/stretchy/relations/query_methods/order.rb +63 -0
- data/lib/stretchy/relations/query_methods/query_string.rb +44 -0
- data/lib/stretchy/relations/query_methods/regexp.rb +61 -0
- data/lib/stretchy/relations/query_methods/should.rb +51 -0
- data/lib/stretchy/relations/query_methods/size.rb +44 -0
- data/lib/stretchy/relations/query_methods/skip_callbacks.rb +47 -0
- data/lib/stretchy/relations/query_methods/source.rb +59 -0
- data/lib/stretchy/relations/query_methods/where.rb +113 -0
- data/lib/stretchy/relations/query_methods.rb +51 -540
- data/lib/stretchy/relations/scoping/default.rb +136 -0
- data/lib/stretchy/relations/scoping/named.rb +70 -0
- data/lib/stretchy/relations/scoping/scope_registry.rb +36 -0
- data/lib/stretchy/relations/scoping.rb +30 -0
- data/lib/stretchy/relations/search_option_methods.rb +2 -0
- data/lib/stretchy/shared_scopes.rb +6 -1
- data/lib/stretchy/version.rb +1 -1
- data/lib/stretchy.rb +23 -11
- metadata +147 -18
- data/lib/rails/instrumentation/publishers.rb +0 -29
- data/lib/stretchy/common.rb +0 -33
- data/lib/stretchy/null_relation.rb +0 -53
- data/lib/stretchy/persistence.rb +0 -43
- data/lib/stretchy/refreshable.rb +0 -15
- data/lib/stretchy/scoping/default.rb +0 -134
- data/lib/stretchy/scoping/named.rb +0 -68
- data/lib/stretchy/scoping/scope_registry.rb +0 -34
- data/lib/stretchy/scoping.rb +0 -28
@@ -0,0 +1,136 @@
|
|
1
|
+
module Stretchy
|
2
|
+
module Relations
|
3
|
+
module Scoping
|
4
|
+
module Default
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
included do
|
8
|
+
# Stores the default scope for the class.
|
9
|
+
class_attribute :default_scopes, instance_writer: false, instance_predicate: false
|
10
|
+
|
11
|
+
self.default_scopes = []
|
12
|
+
end
|
13
|
+
|
14
|
+
module ClassMethods
|
15
|
+
# Returns a scope for the model without the previously set scopes.
|
16
|
+
#
|
17
|
+
# class Post < ActiveRecord::Base
|
18
|
+
# def self.default_scope
|
19
|
+
# where published: true
|
20
|
+
# end
|
21
|
+
# end
|
22
|
+
#
|
23
|
+
# Post.all # Fires "SELECT * FROM posts WHERE published = true"
|
24
|
+
# Post.unscoped.all # Fires "SELECT * FROM posts"
|
25
|
+
# Post.where(published: false).unscoped.all # Fires "SELECT * FROM posts"
|
26
|
+
#
|
27
|
+
# This method also accepts a block. All queries inside the block will
|
28
|
+
# not use the previously set scopes.
|
29
|
+
#
|
30
|
+
# Post.unscoped {
|
31
|
+
# Post.limit(10) # Fires "SELECT * FROM posts LIMIT 10"
|
32
|
+
# }
|
33
|
+
def unscoped
|
34
|
+
block_given? ? relation.scoping { yield } : relation
|
35
|
+
end
|
36
|
+
|
37
|
+
def before_remove_const #:nodoc:
|
38
|
+
self.current_scope = nil
|
39
|
+
end
|
40
|
+
|
41
|
+
protected
|
42
|
+
|
43
|
+
# Use this macro in your model to set a default scope for all operations on
|
44
|
+
# the model.
|
45
|
+
#
|
46
|
+
# class Article < ActiveRecord::Base
|
47
|
+
# default_scope { where(published: true) }
|
48
|
+
# end
|
49
|
+
#
|
50
|
+
# Article.all # => SELECT * FROM articles WHERE published = true
|
51
|
+
#
|
52
|
+
# The +default_scope+ is also applied while creating/building a record.
|
53
|
+
# It is not applied while updating a record.
|
54
|
+
#
|
55
|
+
# Article.new.published # => true
|
56
|
+
# Article.create.published # => true
|
57
|
+
#
|
58
|
+
# (You can also pass any object which responds to +call+ to the
|
59
|
+
# +default_scope+ macro, and it will be called when building the
|
60
|
+
# default scope.)
|
61
|
+
#
|
62
|
+
# If you use multiple +default_scope+ declarations in your model then
|
63
|
+
# they will be merged together:
|
64
|
+
#
|
65
|
+
# class Article < ActiveRecord::Base
|
66
|
+
# default_scope { where(published: true) }
|
67
|
+
# default_scope { where(rating: 'G') }
|
68
|
+
# end
|
69
|
+
#
|
70
|
+
# Article.all # => SELECT * FROM articles WHERE published = true AND rating = 'G'
|
71
|
+
#
|
72
|
+
# This is also the case with inheritance and module includes where the
|
73
|
+
# parent or module defines a +default_scope+ and the child or including
|
74
|
+
# class defines a second one.
|
75
|
+
#
|
76
|
+
# If you need to do more complex things with a default scope, you can
|
77
|
+
# alternatively define it as a class method:
|
78
|
+
#
|
79
|
+
# class Article < ActiveRecord::Base
|
80
|
+
# def self.default_scope
|
81
|
+
# # Should return a scope, you can call 'super' here etc.
|
82
|
+
# end
|
83
|
+
# end
|
84
|
+
def default_scope(scope = nil)
|
85
|
+
scope = Proc.new if block_given?
|
86
|
+
|
87
|
+
if scope.is_a?(Relation) || !scope.respond_to?(:call)
|
88
|
+
raise ArgumentError,
|
89
|
+
"Support for calling #default_scope without a block is removed. For example instead " \
|
90
|
+
"of `default_scope where(color: 'red')`, please use " \
|
91
|
+
"`default_scope { where(color: 'red') }`. (Alternatively you can just redefine " \
|
92
|
+
"self.default_scope.)"
|
93
|
+
end
|
94
|
+
|
95
|
+
self.default_scopes += [scope]
|
96
|
+
end
|
97
|
+
|
98
|
+
def build_default_scope(base_rel = relation) # :nodoc:
|
99
|
+
if !self.is_a?(method(:default_scope).owner)
|
100
|
+
# The user has defined their own default scope method, so call that
|
101
|
+
evaluate_default_scope { default_scope }
|
102
|
+
elsif default_scopes.any?
|
103
|
+
evaluate_default_scope do
|
104
|
+
default_scopes.inject(base_rel) do |default_scope, scope|
|
105
|
+
default_scope.merge(base_rel.scoping { scope.call })
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
def ignore_default_scope? # :nodoc:
|
112
|
+
ScopeRegistry.value_for(:ignore_default_scope, self)
|
113
|
+
end
|
114
|
+
|
115
|
+
def ignore_default_scope=(ignore) # :nodoc:
|
116
|
+
ScopeRegistry.set_value_for(:ignore_default_scope, self, ignore)
|
117
|
+
end
|
118
|
+
|
119
|
+
# The ignore_default_scope flag is used to prevent an infinite recursion
|
120
|
+
# situation where a default scope references a scope which has a default
|
121
|
+
# scope which references a scope...
|
122
|
+
def evaluate_default_scope # :nodoc:
|
123
|
+
return if ignore_default_scope?
|
124
|
+
|
125
|
+
begin
|
126
|
+
self.ignore_default_scope = true
|
127
|
+
yield
|
128
|
+
ensure
|
129
|
+
self.ignore_default_scope = false
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
module Stretchy
|
2
|
+
module Relations
|
3
|
+
module Scoping
|
4
|
+
module Named
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
module ClassMethods
|
8
|
+
def all(options={})
|
9
|
+
if current_scope
|
10
|
+
current_scope.clone
|
11
|
+
else
|
12
|
+
default_scoped
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def default_scoped # :nodoc:
|
17
|
+
relation.merge(build_default_scope)
|
18
|
+
end
|
19
|
+
|
20
|
+
# Collects attributes from scopes that should be applied when creating
|
21
|
+
# an AR instance for the particular class this is called on.
|
22
|
+
def scope_attributes # :nodoc:
|
23
|
+
all.scope_for_create
|
24
|
+
end
|
25
|
+
|
26
|
+
# Are there default attributes associated with this scope?
|
27
|
+
def scope_attributes? # :nodoc:
|
28
|
+
current_scope || default_scopes.any?
|
29
|
+
end
|
30
|
+
|
31
|
+
def scope(name, body, &block)
|
32
|
+
if dangerous_class_method?(name)
|
33
|
+
raise ArgumentError, "You tried to define a scope named \"#{name}\" " \
|
34
|
+
"on the model \"#{self.name}\", but there's already defined " \
|
35
|
+
"a class method with the same name."
|
36
|
+
end
|
37
|
+
|
38
|
+
extension = Module.new(&block) if block
|
39
|
+
|
40
|
+
singleton_class.send(:define_method, name) do |*args|
|
41
|
+
scope = all.scoping { body.call(*args) }
|
42
|
+
scope = scope.extending(extension) if extension
|
43
|
+
|
44
|
+
scope || all
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
BLACKLISTED_CLASS_METHODS = %w(private public protected allocate new name parent superclass)
|
49
|
+
|
50
|
+
private
|
51
|
+
def dangerous_class_method?(method_name)
|
52
|
+
BLACKLISTED_CLASS_METHODS.include?(method_name.to_s) || class_method_defined_within?(method_name, Model, self.superclass)
|
53
|
+
end
|
54
|
+
|
55
|
+
def class_method_defined_within?(name, klass, superklass = klass.superclass) # :nodoc
|
56
|
+
if klass.respond_to?(name, true)
|
57
|
+
if superklass.respond_to?(name, true)
|
58
|
+
klass.method(name).owner != superklass.method(name).owner
|
59
|
+
else
|
60
|
+
true
|
61
|
+
end
|
62
|
+
else
|
63
|
+
false
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Stretchy
|
2
|
+
module Relations
|
3
|
+
module Scoping
|
4
|
+
class ScopeRegistry # :nodoc:
|
5
|
+
# extend ActiveSupport::PerThreadRegistry
|
6
|
+
thread_mattr_accessor :registry
|
7
|
+
|
8
|
+
VALID_SCOPE_TYPES = [:current_scope, :ignore_default_scope]
|
9
|
+
|
10
|
+
# def initialize
|
11
|
+
self.registry = Hash.new { |hash, key| hash[key] = {} }
|
12
|
+
# end
|
13
|
+
|
14
|
+
# Obtains the value for a given +scope_name+ and +variable_name+.
|
15
|
+
def self.value_for(scope_type, variable_name)
|
16
|
+
raise_invalid_scope_type!(scope_type)
|
17
|
+
self.registry[scope_type][variable_name]
|
18
|
+
end
|
19
|
+
|
20
|
+
# Sets the +value+ for a given +scope_type+ and +variable_name+.
|
21
|
+
def self.set_value_for(scope_type, variable_name, value)
|
22
|
+
raise_invalid_scope_type!(scope_type)
|
23
|
+
self.registry[scope_type][variable_name] = value
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def raise_invalid_scope_type!(scope_type)
|
29
|
+
if !VALID_SCOPE_TYPES.include?(scope_type)
|
30
|
+
raise ArgumentError, "Invalid scope type '#{scope_type}' sent to the registry. Scope types must be included in VALID_SCOPE_TYPES"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Stretchy
|
2
|
+
module Relations
|
3
|
+
module Scoping
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
include Default
|
8
|
+
include Named
|
9
|
+
end
|
10
|
+
|
11
|
+
module ClassMethods
|
12
|
+
def base_class
|
13
|
+
self
|
14
|
+
end
|
15
|
+
|
16
|
+
def current_scope
|
17
|
+
ScopeRegistry.new.registry[:current_scope][base_class.to_s]
|
18
|
+
# ScopeRegistry.value_for(:current_scope, base_class.to_s)
|
19
|
+
end
|
20
|
+
|
21
|
+
def current_scope=(scope) #:nodoc:
|
22
|
+
ScopeRegistry.new.registry[:current_scope][base_class.to_s] = scope
|
23
|
+
# ScopeRegistry.set_value_for(:current_scope, base_class.to_s, scope)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -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
|
|
@@ -40,28 +41,39 @@ module Stretchy
|
|
40
41
|
|
41
42
|
class Configuration
|
42
43
|
|
43
|
-
attr_accessor :
|
44
|
-
|
44
|
+
attr_accessor :options
|
45
|
+
|
46
|
+
delegate_missing_to :@options
|
45
47
|
|
46
48
|
def initialize
|
47
|
-
@
|
48
|
-
|
49
|
+
@options = Hashie::Mash.new(
|
50
|
+
default_keyword_field: :keyword,
|
51
|
+
add_keyword_field_to_text_attributes: true,
|
52
|
+
auto_target_keywords: true,
|
53
|
+
opensearch: false,
|
54
|
+
client: Elasticsearch::Client.new(url: 'http://localhost:9200')
|
55
|
+
)
|
49
56
|
end
|
50
57
|
|
51
|
-
def client=(
|
52
|
-
@client =
|
53
|
-
self.opensearch = true if
|
58
|
+
def client=(klient)
|
59
|
+
@options[:client] = klient
|
60
|
+
self.opensearch = true if klient.class.name =~ /OpenSearch/
|
61
|
+
end
|
62
|
+
|
63
|
+
def search_backend_const
|
64
|
+
self.opensearch? ? OpenSearch : Elasticsearch
|
54
65
|
end
|
55
66
|
|
56
67
|
def opensearch=(bool)
|
57
|
-
@opensearch = bool
|
68
|
+
@options[:opensearch] = bool
|
58
69
|
OpenSearchCompatibility.opensearch_patch! if bool
|
59
70
|
end
|
60
71
|
|
61
72
|
def opensearch?
|
62
|
-
@opensearch
|
73
|
+
@options[:opensearch]
|
63
74
|
end
|
64
75
|
|
76
|
+
|
65
77
|
end
|
66
78
|
|
67
79
|
class << self
|
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.6
|
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-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: zeitwerk
|
@@ -151,33 +151,33 @@ dependencies:
|
|
151
151
|
- !ruby/object:Gem::Version
|
152
152
|
version: 0.21.2
|
153
153
|
- !ruby/object:Gem::Dependency
|
154
|
-
name:
|
154
|
+
name: opensearch-ruby
|
155
155
|
requirement: !ruby/object:Gem::Requirement
|
156
156
|
requirements:
|
157
157
|
- - "~>"
|
158
158
|
- !ruby/object:Gem::Version
|
159
|
-
version: 0
|
159
|
+
version: '3.0'
|
160
160
|
type: :development
|
161
161
|
prerelease: false
|
162
162
|
version_requirements: !ruby/object:Gem::Requirement
|
163
163
|
requirements:
|
164
164
|
- - "~>"
|
165
165
|
- !ruby/object:Gem::Version
|
166
|
-
version: 0
|
166
|
+
version: '3.0'
|
167
167
|
- !ruby/object:Gem::Dependency
|
168
|
-
name:
|
168
|
+
name: rdoc-markdown
|
169
169
|
requirement: !ruby/object:Gem::Requirement
|
170
170
|
requirements:
|
171
171
|
- - "~>"
|
172
172
|
- !ruby/object:Gem::Version
|
173
|
-
version:
|
173
|
+
version: 0.4.2
|
174
174
|
type: :development
|
175
175
|
prerelease: false
|
176
176
|
version_requirements: !ruby/object:Gem::Requirement
|
177
177
|
requirements:
|
178
178
|
- - "~>"
|
179
179
|
- !ruby/object:Gem::Version
|
180
|
-
version:
|
180
|
+
version: 0.4.2
|
181
181
|
- !ruby/object:Gem::Dependency
|
182
182
|
name: octokit
|
183
183
|
requirement: !ruby/object:Gem::Requirement
|
@@ -206,6 +206,34 @@ 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'
|
223
|
+
- !ruby/object:Gem::Dependency
|
224
|
+
name: rdoc
|
225
|
+
requirement: !ruby/object:Gem::Requirement
|
226
|
+
requirements:
|
227
|
+
- - "~>"
|
228
|
+
- !ruby/object:Gem::Version
|
229
|
+
version: 6.6.3
|
230
|
+
type: :development
|
231
|
+
prerelease: false
|
232
|
+
version_requirements: !ruby/object:Gem::Requirement
|
233
|
+
requirements:
|
234
|
+
- - "~>"
|
235
|
+
- !ruby/object:Gem::Version
|
236
|
+
version: 6.6.3
|
209
237
|
description: Provides a familiar ActiveRecord-like interface for working with Elasticsearch
|
210
238
|
email:
|
211
239
|
- spencer.markowski@theablefew.com
|
@@ -224,8 +252,44 @@ files:
|
|
224
252
|
- containers/Dockerfile.elasticsearch
|
225
253
|
- containers/Dockerfile.opensearch
|
226
254
|
- docker-compose.yml
|
227
|
-
-
|
228
|
-
-
|
255
|
+
- docs/.nojekyll
|
256
|
+
- docs/README.md
|
257
|
+
- docs/_coverpage.md
|
258
|
+
- docs/_sidebar.md
|
259
|
+
- docs/examples/_sidebar.md
|
260
|
+
- docs/examples/data_analysis.md
|
261
|
+
- docs/examples/semantic_search_with_llm.md
|
262
|
+
- docs/examples/simple-ingest-pipeline.md
|
263
|
+
- docs/guides/_sidebar.md
|
264
|
+
- docs/guides/aggregations.md
|
265
|
+
- docs/guides/machine-learning.md
|
266
|
+
- docs/guides/models.md
|
267
|
+
- docs/guides/pipelines.md
|
268
|
+
- docs/guides/querying.md
|
269
|
+
- docs/guides/quick-start.md
|
270
|
+
- docs/guides/scopes.md
|
271
|
+
- docs/index.html
|
272
|
+
- docs/stretchy.cover.png
|
273
|
+
- docs/stretchy.logo.png
|
274
|
+
- docs/styles.css
|
275
|
+
- lib/elasticsearch/api/actions/machine_learning/models/delete_model.rb
|
276
|
+
- lib/elasticsearch/api/actions/machine_learning/models/deploy.rb
|
277
|
+
- lib/elasticsearch/api/actions/machine_learning/models/get_model.rb
|
278
|
+
- lib/elasticsearch/api/actions/machine_learning/models/get_status.rb
|
279
|
+
- lib/elasticsearch/api/actions/machine_learning/models/params_registry.rb
|
280
|
+
- lib/elasticsearch/api/actions/machine_learning/models/register.rb
|
281
|
+
- lib/elasticsearch/api/actions/machine_learning/models/undeploy.rb
|
282
|
+
- lib/elasticsearch/api/actions/machine_learning/models/update_model.rb
|
283
|
+
- lib/elasticsearch/api/namespace/machine_learning/model.rb
|
284
|
+
- lib/opensearch/api/actions/machine_learning/models/delete_model.rb
|
285
|
+
- lib/opensearch/api/actions/machine_learning/models/deploy.rb
|
286
|
+
- lib/opensearch/api/actions/machine_learning/models/get_model.rb
|
287
|
+
- lib/opensearch/api/actions/machine_learning/models/get_status.rb
|
288
|
+
- lib/opensearch/api/actions/machine_learning/models/params_registry.rb
|
289
|
+
- lib/opensearch/api/actions/machine_learning/models/register.rb
|
290
|
+
- lib/opensearch/api/actions/machine_learning/models/undeploy.rb
|
291
|
+
- lib/opensearch/api/actions/machine_learning/models/update_model.rb
|
292
|
+
- lib/opensearch/api/namespace/machine_learning/model.rb
|
229
293
|
- lib/stretchy.rb
|
230
294
|
- lib/stretchy/associations.rb
|
231
295
|
- lib/stretchy/associations/associated_validator.rb
|
@@ -248,6 +312,7 @@ files:
|
|
248
312
|
- lib/stretchy/attributes/type/ip.rb
|
249
313
|
- lib/stretchy/attributes/type/join.rb
|
250
314
|
- lib/stretchy/attributes/type/keyword.rb
|
315
|
+
- lib/stretchy/attributes/type/knn_vector.rb
|
251
316
|
- lib/stretchy/attributes/type/match_only_text.rb
|
252
317
|
- lib/stretchy/attributes/type/nested.rb
|
253
318
|
- lib/stretchy/attributes/type/numeric/base.rb
|
@@ -279,31 +344,95 @@ files:
|
|
279
344
|
- lib/stretchy/attributes/type/token_count.rb
|
280
345
|
- lib/stretchy/attributes/type/version.rb
|
281
346
|
- lib/stretchy/attributes/type/wildcard.rb
|
282
|
-
- lib/stretchy/common.rb
|
283
347
|
- lib/stretchy/delegation/delegate_cache.rb
|
284
348
|
- lib/stretchy/delegation/gateway_delegation.rb
|
349
|
+
- lib/stretchy/index_setting.rb
|
285
350
|
- lib/stretchy/indexing/bulk.rb
|
351
|
+
- lib/stretchy/machine_learning/model.rb
|
286
352
|
- lib/stretchy/model/callbacks.rb
|
353
|
+
- lib/stretchy/model/common.rb
|
354
|
+
- lib/stretchy/model/persistence.rb
|
355
|
+
- lib/stretchy/model/refreshable.rb
|
287
356
|
- lib/stretchy/model/serialization.rb
|
288
|
-
- lib/stretchy/null_relation.rb
|
289
357
|
- lib/stretchy/open_search_compatibility.rb
|
290
|
-
- lib/stretchy/
|
358
|
+
- lib/stretchy/pipeline.rb
|
359
|
+
- lib/stretchy/pipelines/processor.rb
|
291
360
|
- lib/stretchy/querying.rb
|
361
|
+
- lib/stretchy/rails/instrumentation/publishers.rb
|
362
|
+
- lib/stretchy/rails/instrumentation/railtie.rb
|
292
363
|
- lib/stretchy/record.rb
|
293
|
-
- lib/stretchy/refreshable.rb
|
294
364
|
- lib/stretchy/relation.rb
|
295
365
|
- lib/stretchy/relations/aggregation_methods.rb
|
366
|
+
- lib/stretchy/relations/aggregation_methods/aggregation.rb
|
367
|
+
- lib/stretchy/relations/aggregation_methods/avg.rb
|
368
|
+
- lib/stretchy/relations/aggregation_methods/bucket_script.rb
|
369
|
+
- lib/stretchy/relations/aggregation_methods/bucket_selector.rb
|
370
|
+
- lib/stretchy/relations/aggregation_methods/bucket_sort.rb
|
371
|
+
- lib/stretchy/relations/aggregation_methods/cardinality.rb
|
372
|
+
- lib/stretchy/relations/aggregation_methods/children.rb
|
373
|
+
- lib/stretchy/relations/aggregation_methods/composite.rb
|
374
|
+
- lib/stretchy/relations/aggregation_methods/date_histogram.rb
|
375
|
+
- lib/stretchy/relations/aggregation_methods/date_range.rb
|
376
|
+
- lib/stretchy/relations/aggregation_methods/extended_stats.rb
|
377
|
+
- lib/stretchy/relations/aggregation_methods/filter.rb
|
378
|
+
- lib/stretchy/relations/aggregation_methods/filters.rb
|
379
|
+
- lib/stretchy/relations/aggregation_methods/geo_bounds.rb
|
380
|
+
- lib/stretchy/relations/aggregation_methods/geo_centroid.rb
|
381
|
+
- lib/stretchy/relations/aggregation_methods/global.rb
|
382
|
+
- lib/stretchy/relations/aggregation_methods/histogram.rb
|
383
|
+
- lib/stretchy/relations/aggregation_methods/ip_range.rb
|
384
|
+
- lib/stretchy/relations/aggregation_methods/max.rb
|
385
|
+
- lib/stretchy/relations/aggregation_methods/min.rb
|
386
|
+
- lib/stretchy/relations/aggregation_methods/missing.rb
|
387
|
+
- lib/stretchy/relations/aggregation_methods/nested.rb
|
388
|
+
- lib/stretchy/relations/aggregation_methods/percentile_ranks.rb
|
389
|
+
- lib/stretchy/relations/aggregation_methods/percentiles.rb
|
390
|
+
- lib/stretchy/relations/aggregation_methods/range.rb
|
391
|
+
- lib/stretchy/relations/aggregation_methods/reverse_nested.rb
|
392
|
+
- lib/stretchy/relations/aggregation_methods/sampler.rb
|
393
|
+
- lib/stretchy/relations/aggregation_methods/scripted_metric.rb
|
394
|
+
- lib/stretchy/relations/aggregation_methods/significant_terms.rb
|
395
|
+
- lib/stretchy/relations/aggregation_methods/stats.rb
|
396
|
+
- lib/stretchy/relations/aggregation_methods/sum.rb
|
397
|
+
- lib/stretchy/relations/aggregation_methods/terms.rb
|
398
|
+
- lib/stretchy/relations/aggregation_methods/top_hits.rb
|
399
|
+
- lib/stretchy/relations/aggregation_methods/top_metrics.rb
|
400
|
+
- lib/stretchy/relations/aggregation_methods/value_count.rb
|
401
|
+
- lib/stretchy/relations/aggregation_methods/weighted_avg.rb
|
296
402
|
- lib/stretchy/relations/finder_methods.rb
|
297
403
|
- lib/stretchy/relations/merger.rb
|
404
|
+
- lib/stretchy/relations/null_relation.rb
|
298
405
|
- lib/stretchy/relations/query_builder.rb
|
299
406
|
- lib/stretchy/relations/query_methods.rb
|
407
|
+
- lib/stretchy/relations/query_methods/bind.rb
|
408
|
+
- lib/stretchy/relations/query_methods/extending.rb
|
409
|
+
- lib/stretchy/relations/query_methods/fields.rb
|
410
|
+
- lib/stretchy/relations/query_methods/filter_query.rb
|
411
|
+
- lib/stretchy/relations/query_methods/has_field.rb
|
412
|
+
- lib/stretchy/relations/query_methods/highlight.rb
|
413
|
+
- lib/stretchy/relations/query_methods/hybrid.rb
|
414
|
+
- lib/stretchy/relations/query_methods/ids.rb
|
415
|
+
- lib/stretchy/relations/query_methods/match.rb
|
416
|
+
- lib/stretchy/relations/query_methods/must_not.rb
|
417
|
+
- lib/stretchy/relations/query_methods/neural.rb
|
418
|
+
- lib/stretchy/relations/query_methods/neural_sparse.rb
|
419
|
+
- lib/stretchy/relations/query_methods/none.rb
|
420
|
+
- lib/stretchy/relations/query_methods/or_filter.rb
|
421
|
+
- lib/stretchy/relations/query_methods/order.rb
|
422
|
+
- lib/stretchy/relations/query_methods/query_string.rb
|
423
|
+
- lib/stretchy/relations/query_methods/regexp.rb
|
424
|
+
- lib/stretchy/relations/query_methods/should.rb
|
425
|
+
- lib/stretchy/relations/query_methods/size.rb
|
426
|
+
- lib/stretchy/relations/query_methods/skip_callbacks.rb
|
427
|
+
- lib/stretchy/relations/query_methods/source.rb
|
428
|
+
- lib/stretchy/relations/query_methods/where.rb
|
429
|
+
- lib/stretchy/relations/scoping.rb
|
430
|
+
- lib/stretchy/relations/scoping/default.rb
|
431
|
+
- lib/stretchy/relations/scoping/named.rb
|
432
|
+
- lib/stretchy/relations/scoping/scope_registry.rb
|
300
433
|
- lib/stretchy/relations/search_option_methods.rb
|
301
434
|
- lib/stretchy/relations/spawn_methods.rb
|
302
435
|
- lib/stretchy/repository.rb
|
303
|
-
- lib/stretchy/scoping.rb
|
304
|
-
- lib/stretchy/scoping/default.rb
|
305
|
-
- lib/stretchy/scoping/named.rb
|
306
|
-
- lib/stretchy/scoping/scope_registry.rb
|
307
436
|
- lib/stretchy/shared_scopes.rb
|
308
437
|
- lib/stretchy/utils.rb
|
309
438
|
- lib/stretchy/version.rb
|
@@ -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
|
data/lib/stretchy/common.rb
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
module Stretchy
|
2
|
-
module Common
|
3
|
-
extend ActiveSupport::Concern
|
4
|
-
|
5
|
-
def highlights_for(attribute)
|
6
|
-
highlights[attribute.to_s]
|
7
|
-
end
|
8
|
-
|
9
|
-
class_methods do
|
10
|
-
|
11
|
-
# Set the default sort key to be used in sort operations
|
12
|
-
#
|
13
|
-
def default_sort_key(field = nil)
|
14
|
-
@default_sort_key = field unless field.nil?
|
15
|
-
@default_sort_key
|
16
|
-
end
|
17
|
-
|
18
|
-
def default_size(size = nil)
|
19
|
-
@default_size = size unless size.nil?
|
20
|
-
@default_size
|
21
|
-
end
|
22
|
-
|
23
|
-
private
|
24
|
-
|
25
|
-
# Return a Relation instance to chain queries
|
26
|
-
#
|
27
|
-
def relation
|
28
|
-
Relation.create(self, {})
|
29
|
-
end
|
30
|
-
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|