stretchy-model 0.6.5 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (212) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +2 -1
  3. data/README.md +28 -10
  4. data/Rakefile +56 -0
  5. data/docs/.nojekyll +0 -0
  6. data/docs/README.md +147 -0
  7. data/docs/_coverpage.md +14 -0
  8. data/docs/_sidebar.md +15 -0
  9. data/docs/examples/_sidebar.md +15 -0
  10. data/docs/examples/data_analysis.md +216 -0
  11. data/docs/examples/neural_search_with_llm.md +381 -0
  12. data/docs/examples/simple-ingest-pipeline.md +326 -0
  13. data/docs/guides/_sidebar.md +15 -0
  14. data/docs/guides/aggregations.md +142 -0
  15. data/docs/guides/machine-learning.md +154 -0
  16. data/docs/guides/models.md +372 -0
  17. data/docs/guides/pipelines.md +151 -0
  18. data/docs/guides/querying.md +361 -0
  19. data/docs/guides/quick-start.md +72 -0
  20. data/docs/guides/scopes.md +125 -0
  21. data/docs/index.html +113 -0
  22. data/docs/stretchy.cover.png +0 -0
  23. data/docs/stretchy.logo.png +0 -0
  24. data/docs/styles.css +90 -0
  25. data/lib/elasticsearch/api/actions/connector/check_in.rb +64 -0
  26. data/lib/elasticsearch/api/actions/connector/delete.rb +64 -0
  27. data/lib/elasticsearch/api/actions/connector/get.rb +64 -0
  28. data/lib/elasticsearch/api/actions/connector/last_sync.rb +66 -0
  29. data/lib/elasticsearch/api/actions/connector/list.rb +60 -0
  30. data/lib/elasticsearch/api/actions/connector/post.rb +57 -0
  31. data/lib/elasticsearch/api/actions/connector/put.rb +66 -0
  32. data/lib/elasticsearch/api/actions/connector/update_api_key_id.rb +66 -0
  33. data/lib/elasticsearch/api/actions/connector/update_configuration.rb +66 -0
  34. data/lib/elasticsearch/api/actions/connector/update_error.rb +66 -0
  35. data/lib/elasticsearch/api/actions/connector/update_filtering.rb +66 -0
  36. data/lib/elasticsearch/api/actions/connector/update_index_name.rb +66 -0
  37. data/lib/elasticsearch/api/actions/connector/update_name.rb +66 -0
  38. data/lib/elasticsearch/api/actions/connector/update_native.rb +66 -0
  39. data/lib/elasticsearch/api/actions/connector/update_pipeline.rb +66 -0
  40. data/lib/elasticsearch/api/actions/connector/update_scheduling.rb +66 -0
  41. data/lib/elasticsearch/api/actions/connector/update_service_type.rb +66 -0
  42. data/lib/elasticsearch/api/actions/connector/update_status.rb +66 -0
  43. data/lib/elasticsearch/api/namespace/connector.rb +36 -0
  44. data/lib/opensearch/api/actions/machine_learning/connector/delete.rb +42 -0
  45. data/lib/opensearch/api/actions/machine_learning/connector/get.rb +42 -0
  46. data/lib/opensearch/api/actions/machine_learning/connector/list.rb +38 -0
  47. data/lib/opensearch/api/actions/machine_learning/connector/post.rb +35 -0
  48. data/lib/opensearch/api/actions/machine_learning/connector/put.rb +44 -0
  49. data/lib/opensearch/api/actions/machine_learning/models/predict.rb +32 -0
  50. data/lib/opensearch/api/namespace/connector.rb +19 -0
  51. data/lib/stretchy/attributes/transformers/keyword_transformer.rb +41 -35
  52. data/lib/stretchy/attributes/type/array.rb +24 -1
  53. data/lib/stretchy/attributes/type/base.rb +6 -2
  54. data/lib/stretchy/attributes/type/binary.rb +24 -17
  55. data/lib/stretchy/attributes/type/boolean.rb +29 -22
  56. data/lib/stretchy/attributes/type/completion.rb +18 -10
  57. data/lib/stretchy/attributes/type/constant_keyword.rb +35 -26
  58. data/lib/stretchy/attributes/type/date_time.rb +28 -17
  59. data/lib/stretchy/attributes/type/dense_vector.rb +46 -49
  60. data/lib/stretchy/attributes/type/flattened.rb +28 -19
  61. data/lib/stretchy/attributes/type/geo_point.rb +21 -12
  62. data/lib/stretchy/attributes/type/geo_shape.rb +21 -12
  63. data/lib/stretchy/attributes/type/hash.rb +24 -10
  64. data/lib/stretchy/attributes/type/histogram.rb +25 -0
  65. data/lib/stretchy/attributes/type/ip.rb +26 -17
  66. data/lib/stretchy/attributes/type/join.rb +16 -7
  67. data/lib/stretchy/attributes/type/keyword.rb +21 -26
  68. data/lib/stretchy/attributes/type/knn_vector.rb +47 -0
  69. data/lib/stretchy/attributes/type/match_only_text.rb +22 -1
  70. data/lib/stretchy/attributes/type/nested.rb +16 -11
  71. data/lib/stretchy/attributes/type/numeric/base.rb +30 -22
  72. data/lib/stretchy/attributes/type/numeric/byte.rb +20 -0
  73. data/lib/stretchy/attributes/type/numeric/double.rb +20 -0
  74. data/lib/stretchy/attributes/type/numeric/float.rb +20 -0
  75. data/lib/stretchy/attributes/type/numeric/half_float.rb +20 -0
  76. data/lib/stretchy/attributes/type/numeric/integer.rb +21 -1
  77. data/lib/stretchy/attributes/type/numeric/long.rb +20 -0
  78. data/lib/stretchy/attributes/type/numeric/scaled_float.rb +16 -7
  79. data/lib/stretchy/attributes/type/numeric/short.rb +20 -0
  80. data/lib/stretchy/attributes/type/numeric/unsigned_long.rb +21 -1
  81. data/lib/stretchy/attributes/type/percolator.rb +16 -4
  82. data/lib/stretchy/attributes/type/point.rb +19 -9
  83. data/lib/stretchy/attributes/type/range/base.rb +24 -1
  84. data/lib/stretchy/attributes/type/range/date_range.rb +21 -5
  85. data/lib/stretchy/attributes/type/range/double_range.rb +20 -4
  86. data/lib/stretchy/attributes/type/range/float_range.rb +21 -5
  87. data/lib/stretchy/attributes/type/range/integer_range.rb +20 -4
  88. data/lib/stretchy/attributes/type/range/ip_range.rb +20 -4
  89. data/lib/stretchy/attributes/type/range/long_range.rb +20 -4
  90. data/lib/stretchy/attributes/type/rank_feature.rb +16 -6
  91. data/lib/stretchy/attributes/type/rank_features.rb +16 -9
  92. data/lib/stretchy/attributes/type/search_as_you_type.rb +28 -18
  93. data/lib/stretchy/attributes/type/shape.rb +19 -9
  94. data/lib/stretchy/attributes/type/sparse_vector.rb +25 -21
  95. data/lib/stretchy/attributes/type/string.rb +42 -1
  96. data/lib/stretchy/attributes/type/text.rb +53 -28
  97. data/lib/stretchy/attributes/type/token_count.rb +21 -11
  98. data/lib/stretchy/attributes/type/version.rb +16 -6
  99. data/lib/stretchy/attributes/type/wildcard.rb +36 -25
  100. data/lib/stretchy/attributes.rb +29 -0
  101. data/lib/stretchy/delegation/gateway_delegation.rb +78 -0
  102. data/lib/stretchy/index_setting.rb +94 -0
  103. data/lib/stretchy/indexing/bulk.rb +75 -3
  104. data/lib/stretchy/machine_learning/connector.rb +130 -0
  105. data/lib/stretchy/machine_learning/errors.rb +25 -0
  106. data/lib/stretchy/machine_learning/model.rb +162 -109
  107. data/lib/stretchy/machine_learning/registry.rb +19 -0
  108. data/lib/stretchy/model/callbacks.rb +1 -0
  109. data/lib/stretchy/model/common.rb +157 -0
  110. data/lib/stretchy/model/persistence.rb +144 -0
  111. data/lib/stretchy/model/refreshable.rb +26 -0
  112. data/lib/stretchy/open_search_compatibility.rb +2 -0
  113. data/lib/stretchy/pipeline.rb +2 -1
  114. data/lib/stretchy/pipelines/processor.rb +40 -36
  115. data/lib/stretchy/querying.rb +7 -8
  116. data/lib/stretchy/rails/railtie.rb +11 -0
  117. data/lib/stretchy/rails/tasks/connector/create.rake +32 -0
  118. data/lib/stretchy/rails/tasks/connector/delete.rake +27 -0
  119. data/lib/stretchy/rails/tasks/connector/status.rake +31 -0
  120. data/lib/stretchy/rails/tasks/connector/update.rake +32 -0
  121. data/lib/stretchy/rails/tasks/index/create.rake +28 -0
  122. data/lib/stretchy/rails/tasks/index/delete.rake +27 -0
  123. data/lib/stretchy/rails/tasks/index/status.rake +23 -0
  124. data/lib/stretchy/rails/tasks/ml/delete.rake +25 -0
  125. data/lib/stretchy/rails/tasks/ml/deploy.rake +78 -0
  126. data/lib/stretchy/rails/tasks/ml/status.rake +31 -0
  127. data/lib/stretchy/rails/tasks/pipeline/create.rake +27 -0
  128. data/lib/stretchy/rails/tasks/pipeline/delete.rake +26 -0
  129. data/lib/stretchy/rails/tasks/pipeline/status.rake +25 -0
  130. data/lib/stretchy/rails/tasks/status.rake +15 -0
  131. data/lib/stretchy/rails/tasks/stretchy.rake +42 -0
  132. data/lib/stretchy/record.rb +5 -4
  133. data/lib/stretchy/relation.rb +229 -28
  134. data/lib/stretchy/relations/aggregation_methods/aggregation.rb +59 -0
  135. data/lib/stretchy/relations/aggregation_methods/avg.rb +45 -0
  136. data/lib/stretchy/relations/aggregation_methods/bucket_script.rb +47 -0
  137. data/lib/stretchy/relations/aggregation_methods/bucket_selector.rb +47 -0
  138. data/lib/stretchy/relations/aggregation_methods/bucket_sort.rb +47 -0
  139. data/lib/stretchy/relations/aggregation_methods/cardinality.rb +47 -0
  140. data/lib/stretchy/relations/aggregation_methods/children.rb +47 -0
  141. data/lib/stretchy/relations/aggregation_methods/composite.rb +41 -0
  142. data/lib/stretchy/relations/aggregation_methods/date_histogram.rb +53 -0
  143. data/lib/stretchy/relations/aggregation_methods/date_range.rb +53 -0
  144. data/lib/stretchy/relations/aggregation_methods/extended_stats.rb +48 -0
  145. data/lib/stretchy/relations/aggregation_methods/filter.rb +47 -0
  146. data/lib/stretchy/relations/aggregation_methods/filters.rb +47 -0
  147. data/lib/stretchy/relations/aggregation_methods/geo_bounds.rb +40 -0
  148. data/lib/stretchy/relations/aggregation_methods/geo_centroid.rb +40 -0
  149. data/lib/stretchy/relations/aggregation_methods/global.rb +39 -0
  150. data/lib/stretchy/relations/aggregation_methods/histogram.rb +43 -0
  151. data/lib/stretchy/relations/aggregation_methods/ip_range.rb +41 -0
  152. data/lib/stretchy/relations/aggregation_methods/max.rb +40 -0
  153. data/lib/stretchy/relations/aggregation_methods/min.rb +41 -0
  154. data/lib/stretchy/relations/aggregation_methods/missing.rb +40 -0
  155. data/lib/stretchy/relations/aggregation_methods/nested.rb +40 -0
  156. data/lib/stretchy/relations/aggregation_methods/percentile_ranks.rb +45 -0
  157. data/lib/stretchy/relations/aggregation_methods/percentiles.rb +45 -0
  158. data/lib/stretchy/relations/aggregation_methods/range.rb +42 -0
  159. data/lib/stretchy/relations/aggregation_methods/reverse_nested.rb +40 -0
  160. data/lib/stretchy/relations/aggregation_methods/sampler.rb +40 -0
  161. data/lib/stretchy/relations/aggregation_methods/scripted_metric.rb +43 -0
  162. data/lib/stretchy/relations/aggregation_methods/significant_terms.rb +45 -0
  163. data/lib/stretchy/relations/aggregation_methods/stats.rb +42 -0
  164. data/lib/stretchy/relations/aggregation_methods/sum.rb +42 -0
  165. data/lib/stretchy/relations/aggregation_methods/terms.rb +46 -0
  166. data/lib/stretchy/relations/aggregation_methods/top_hits.rb +42 -0
  167. data/lib/stretchy/relations/aggregation_methods/top_metrics.rb +44 -0
  168. data/lib/stretchy/relations/aggregation_methods/value_count.rb +41 -0
  169. data/lib/stretchy/relations/aggregation_methods/weighted_avg.rb +42 -0
  170. data/lib/stretchy/relations/aggregation_methods.rb +20 -749
  171. data/lib/stretchy/relations/finder_methods.rb +2 -18
  172. data/lib/stretchy/relations/null_relation.rb +55 -0
  173. data/lib/stretchy/relations/query_builder.rb +82 -36
  174. data/lib/stretchy/relations/query_methods/bind.rb +19 -0
  175. data/lib/stretchy/relations/query_methods/extending.rb +29 -0
  176. data/lib/stretchy/relations/query_methods/fields.rb +70 -0
  177. data/lib/stretchy/relations/query_methods/filter_query.rb +53 -0
  178. data/lib/stretchy/relations/query_methods/has_field.rb +40 -0
  179. data/lib/stretchy/relations/query_methods/highlight.rb +75 -0
  180. data/lib/stretchy/relations/query_methods/hybrid.rb +60 -0
  181. data/lib/stretchy/relations/query_methods/ids.rb +40 -0
  182. data/lib/stretchy/relations/query_methods/match.rb +52 -0
  183. data/lib/stretchy/relations/query_methods/must_not.rb +54 -0
  184. data/lib/stretchy/relations/query_methods/neural.rb +58 -0
  185. data/lib/stretchy/relations/query_methods/neural_sparse.rb +43 -0
  186. data/lib/stretchy/relations/query_methods/none.rb +21 -0
  187. data/lib/stretchy/relations/query_methods/or_filter.rb +21 -0
  188. data/lib/stretchy/relations/query_methods/order.rb +63 -0
  189. data/lib/stretchy/relations/query_methods/query_string.rb +44 -0
  190. data/lib/stretchy/relations/query_methods/regexp.rb +61 -0
  191. data/lib/stretchy/relations/query_methods/should.rb +51 -0
  192. data/lib/stretchy/relations/query_methods/size.rb +44 -0
  193. data/lib/stretchy/relations/query_methods/skip_callbacks.rb +47 -0
  194. data/lib/stretchy/relations/query_methods/source.rb +59 -0
  195. data/lib/stretchy/relations/query_methods/where.rb +113 -0
  196. data/lib/stretchy/relations/query_methods.rb +48 -569
  197. data/lib/stretchy/relations/scoping/default.rb +136 -0
  198. data/lib/stretchy/relations/scoping/named.rb +70 -0
  199. data/lib/stretchy/relations/scoping/scope_registry.rb +36 -0
  200. data/lib/stretchy/relations/scoping.rb +30 -0
  201. data/lib/stretchy/relations/search_option_methods.rb +2 -0
  202. data/lib/stretchy/version.rb +1 -1
  203. data/lib/stretchy.rb +24 -10
  204. metadata +170 -17
  205. data/lib/stretchy/common.rb +0 -38
  206. data/lib/stretchy/null_relation.rb +0 -53
  207. data/lib/stretchy/persistence.rb +0 -43
  208. data/lib/stretchy/refreshable.rb +0 -15
  209. data/lib/stretchy/scoping/default.rb +0 -134
  210. data/lib/stretchy/scoping/named.rb +0 -68
  211. data/lib/stretchy/scoping/scope_registry.rb +0 -34
  212. 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,6 +4,8 @@ module Stretchy
4
4
  module SearchOptionMethods
5
5
  extend ActiveSupport::Concern
6
6
 
7
+ METHODS = [:routing, :search_options]
8
+
7
9
  def routing(args)
8
10
  check_if_method_has_arguments!(:routing, args)
9
11
  spawn.routing!(args)
@@ -1,3 +1,3 @@
1
1
  module Stretchy
2
- VERSION = '0.6.5'
2
+ VERSION = '0.7.0'
3
3
  end
data/lib/stretchy.rb CHANGED
@@ -10,7 +10,9 @@ require 'active_support/all'
10
10
 
11
11
  require_relative "stretchy/version"
12
12
  require_relative "stretchy/rails/instrumentation/railtie" if defined?(Rails)
13
+ require_relative "stretchy/rails/railtie" if defined?(Rails)
13
14
  require_relative 'elasticsearch/api/namespace/machine_learning/model'
15
+ require_relative 'elasticsearch/api/namespace/connector'
14
16
 
15
17
  module Stretchy
16
18
 
@@ -27,6 +29,7 @@ module Stretchy
27
29
 
28
30
  def self.boot!
29
31
  loader.setup
32
+ Elasticsearch::API.send(:include, Elasticsearch::API::Connector)
30
33
  Elasticsearch::API.send(:include, Elasticsearch::API::MachineLearning::Models)
31
34
  Stretchy::Attributes.register!
32
35
  end
@@ -35,38 +38,49 @@ module Stretchy
35
38
  Stretchy::Delegation::GatewayDelegation.send(:include, Rails::Instrumentation::Publishers::Record)
36
39
  end
37
40
 
41
+ def self.env
42
+ ENV['RACK_ENV'] || ENV['RAILS_ENV'] || 'development'
43
+ end
44
+
38
45
  module Errors
39
46
  class QueryOptionMissing < StandardError; end
40
47
  end
41
48
 
42
49
  class Configuration
43
50
 
44
- attr_accessor :client
45
- attr_accessor :opensearch
51
+ attr_accessor :options
52
+
53
+ delegate_missing_to :@options
46
54
 
47
55
  def initialize
48
- @client = Elasticsearch::Client.new url: 'http://localhost:9200'
49
- @opensearch = false
56
+ @options = Hashie::Mash.new(
57
+ default_keyword_field: :keyword,
58
+ add_keyword_field_to_text_attributes: true,
59
+ auto_target_keywords: true,
60
+ opensearch: false,
61
+ client: Elasticsearch::Client.new(url: 'http://localhost:9200')
62
+ )
50
63
  end
51
64
 
52
- def client=(client)
53
- @client = client
54
- self.opensearch = true if @client.class.name =~ /OpenSearch/
65
+ def client=(klient)
66
+ @options[:client] = klient
67
+ self.opensearch = true if klient.class.name =~ /OpenSearch/
55
68
  end
56
69
 
57
70
  def search_backend_const
58
- @opensearch ? OpenSearch : Elasticsearch
71
+ self.opensearch? ? OpenSearch : Elasticsearch
59
72
  end
60
73
 
61
74
  def opensearch=(bool)
62
- @opensearch = bool
75
+ @options[:opensearch] = bool
63
76
  OpenSearchCompatibility.opensearch_patch! if bool
64
77
  end
65
78
 
66
79
  def opensearch?
67
- @opensearch
80
+ @options[:opensearch]
68
81
  end
69
82
 
83
+
70
84
  end
71
85
 
72
86
  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.5
4
+ version: 0.7.0
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-20 00:00:00.000000000 Z
11
+ date: 2024-03-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: zeitwerk
@@ -122,6 +122,20 @@ dependencies:
122
122
  - - "~>"
123
123
  - !ruby/object:Gem::Version
124
124
  version: '2.0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: tty-spinner
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '0.9'
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '0.9'
125
139
  - !ruby/object:Gem::Dependency
126
140
  name: rspec
127
141
  requirement: !ruby/object:Gem::Requirement
@@ -151,33 +165,33 @@ dependencies:
151
165
  - !ruby/object:Gem::Version
152
166
  version: 0.21.2
153
167
  - !ruby/object:Gem::Dependency
154
- name: yard
168
+ name: opensearch-ruby
155
169
  requirement: !ruby/object:Gem::Requirement
156
170
  requirements:
157
171
  - - "~>"
158
172
  - !ruby/object:Gem::Version
159
- version: 0.9.36
173
+ version: '3.0'
160
174
  type: :development
161
175
  prerelease: false
162
176
  version_requirements: !ruby/object:Gem::Requirement
163
177
  requirements:
164
178
  - - "~>"
165
179
  - !ruby/object:Gem::Version
166
- version: 0.9.36
180
+ version: '3.0'
167
181
  - !ruby/object:Gem::Dependency
168
- name: opensearch-ruby
182
+ name: rdoc-markdown
169
183
  requirement: !ruby/object:Gem::Requirement
170
184
  requirements:
171
185
  - - "~>"
172
186
  - !ruby/object:Gem::Version
173
- version: '3.0'
187
+ version: 0.4.2
174
188
  type: :development
175
189
  prerelease: false
176
190
  version_requirements: !ruby/object:Gem::Requirement
177
191
  requirements:
178
192
  - - "~>"
179
193
  - !ruby/object:Gem::Version
180
- version: '3.0'
194
+ version: 0.4.2
181
195
  - !ruby/object:Gem::Dependency
182
196
  name: octokit
183
197
  requirement: !ruby/object:Gem::Requirement
@@ -220,6 +234,20 @@ dependencies:
220
234
  - - "~>"
221
235
  - !ruby/object:Gem::Version
222
236
  version: '2.18'
237
+ - !ruby/object:Gem::Dependency
238
+ name: rdoc
239
+ requirement: !ruby/object:Gem::Requirement
240
+ requirements:
241
+ - - "~>"
242
+ - !ruby/object:Gem::Version
243
+ version: 6.6.3
244
+ type: :development
245
+ prerelease: false
246
+ version_requirements: !ruby/object:Gem::Requirement
247
+ requirements:
248
+ - - "~>"
249
+ - !ruby/object:Gem::Version
250
+ version: 6.6.3
223
251
  description: Provides a familiar ActiveRecord-like interface for working with Elasticsearch
224
252
  email:
225
253
  - spencer.markowski@theablefew.com
@@ -238,6 +266,44 @@ files:
238
266
  - containers/Dockerfile.elasticsearch
239
267
  - containers/Dockerfile.opensearch
240
268
  - docker-compose.yml
269
+ - docs/.nojekyll
270
+ - docs/README.md
271
+ - docs/_coverpage.md
272
+ - docs/_sidebar.md
273
+ - docs/examples/_sidebar.md
274
+ - docs/examples/data_analysis.md
275
+ - docs/examples/neural_search_with_llm.md
276
+ - docs/examples/simple-ingest-pipeline.md
277
+ - docs/guides/_sidebar.md
278
+ - docs/guides/aggregations.md
279
+ - docs/guides/machine-learning.md
280
+ - docs/guides/models.md
281
+ - docs/guides/pipelines.md
282
+ - docs/guides/querying.md
283
+ - docs/guides/quick-start.md
284
+ - docs/guides/scopes.md
285
+ - docs/index.html
286
+ - docs/stretchy.cover.png
287
+ - docs/stretchy.logo.png
288
+ - docs/styles.css
289
+ - lib/elasticsearch/api/actions/connector/check_in.rb
290
+ - lib/elasticsearch/api/actions/connector/delete.rb
291
+ - lib/elasticsearch/api/actions/connector/get.rb
292
+ - lib/elasticsearch/api/actions/connector/last_sync.rb
293
+ - lib/elasticsearch/api/actions/connector/list.rb
294
+ - lib/elasticsearch/api/actions/connector/post.rb
295
+ - lib/elasticsearch/api/actions/connector/put.rb
296
+ - lib/elasticsearch/api/actions/connector/update_api_key_id.rb
297
+ - lib/elasticsearch/api/actions/connector/update_configuration.rb
298
+ - lib/elasticsearch/api/actions/connector/update_error.rb
299
+ - lib/elasticsearch/api/actions/connector/update_filtering.rb
300
+ - lib/elasticsearch/api/actions/connector/update_index_name.rb
301
+ - lib/elasticsearch/api/actions/connector/update_name.rb
302
+ - lib/elasticsearch/api/actions/connector/update_native.rb
303
+ - lib/elasticsearch/api/actions/connector/update_pipeline.rb
304
+ - lib/elasticsearch/api/actions/connector/update_scheduling.rb
305
+ - lib/elasticsearch/api/actions/connector/update_service_type.rb
306
+ - lib/elasticsearch/api/actions/connector/update_status.rb
241
307
  - lib/elasticsearch/api/actions/machine_learning/models/delete_model.rb
242
308
  - lib/elasticsearch/api/actions/machine_learning/models/deploy.rb
243
309
  - lib/elasticsearch/api/actions/machine_learning/models/get_model.rb
@@ -246,15 +312,23 @@ files:
246
312
  - lib/elasticsearch/api/actions/machine_learning/models/register.rb
247
313
  - lib/elasticsearch/api/actions/machine_learning/models/undeploy.rb
248
314
  - lib/elasticsearch/api/actions/machine_learning/models/update_model.rb
315
+ - lib/elasticsearch/api/namespace/connector.rb
249
316
  - lib/elasticsearch/api/namespace/machine_learning/model.rb
317
+ - lib/opensearch/api/actions/machine_learning/connector/delete.rb
318
+ - lib/opensearch/api/actions/machine_learning/connector/get.rb
319
+ - lib/opensearch/api/actions/machine_learning/connector/list.rb
320
+ - lib/opensearch/api/actions/machine_learning/connector/post.rb
321
+ - lib/opensearch/api/actions/machine_learning/connector/put.rb
250
322
  - lib/opensearch/api/actions/machine_learning/models/delete_model.rb
251
323
  - lib/opensearch/api/actions/machine_learning/models/deploy.rb
252
324
  - lib/opensearch/api/actions/machine_learning/models/get_model.rb
253
325
  - lib/opensearch/api/actions/machine_learning/models/get_status.rb
254
326
  - lib/opensearch/api/actions/machine_learning/models/params_registry.rb
327
+ - lib/opensearch/api/actions/machine_learning/models/predict.rb
255
328
  - lib/opensearch/api/actions/machine_learning/models/register.rb
256
329
  - lib/opensearch/api/actions/machine_learning/models/undeploy.rb
257
330
  - lib/opensearch/api/actions/machine_learning/models/update_model.rb
331
+ - lib/opensearch/api/namespace/connector.rb
258
332
  - lib/opensearch/api/namespace/machine_learning/model.rb
259
333
  - lib/stretchy.rb
260
334
  - lib/stretchy/associations.rb
@@ -278,6 +352,7 @@ files:
278
352
  - lib/stretchy/attributes/type/ip.rb
279
353
  - lib/stretchy/attributes/type/join.rb
280
354
  - lib/stretchy/attributes/type/keyword.rb
355
+ - lib/stretchy/attributes/type/knn_vector.rb
281
356
  - lib/stretchy/attributes/type/match_only_text.rb
282
357
  - lib/stretchy/attributes/type/nested.rb
283
358
  - lib/stretchy/attributes/type/numeric/base.rb
@@ -309,36 +384,114 @@ files:
309
384
  - lib/stretchy/attributes/type/token_count.rb
310
385
  - lib/stretchy/attributes/type/version.rb
311
386
  - lib/stretchy/attributes/type/wildcard.rb
312
- - lib/stretchy/common.rb
313
387
  - lib/stretchy/delegation/delegate_cache.rb
314
388
  - lib/stretchy/delegation/gateway_delegation.rb
389
+ - lib/stretchy/index_setting.rb
315
390
  - lib/stretchy/indexing/bulk.rb
391
+ - lib/stretchy/machine_learning/connector.rb
392
+ - lib/stretchy/machine_learning/errors.rb
316
393
  - lib/stretchy/machine_learning/model.rb
394
+ - lib/stretchy/machine_learning/registry.rb
317
395
  - lib/stretchy/model/callbacks.rb
396
+ - lib/stretchy/model/common.rb
397
+ - lib/stretchy/model/persistence.rb
398
+ - lib/stretchy/model/refreshable.rb
318
399
  - lib/stretchy/model/serialization.rb
319
- - lib/stretchy/null_relation.rb
320
400
  - lib/stretchy/open_search_compatibility.rb
321
- - lib/stretchy/persistence.rb
322
401
  - lib/stretchy/pipeline.rb
323
402
  - lib/stretchy/pipelines/processor.rb
324
403
  - lib/stretchy/querying.rb
325
404
  - lib/stretchy/rails/instrumentation/publishers.rb
326
405
  - lib/stretchy/rails/instrumentation/railtie.rb
406
+ - lib/stretchy/rails/railtie.rb
407
+ - lib/stretchy/rails/tasks/connector/create.rake
408
+ - lib/stretchy/rails/tasks/connector/delete.rake
409
+ - lib/stretchy/rails/tasks/connector/status.rake
410
+ - lib/stretchy/rails/tasks/connector/update.rake
411
+ - lib/stretchy/rails/tasks/index/create.rake
412
+ - lib/stretchy/rails/tasks/index/delete.rake
413
+ - lib/stretchy/rails/tasks/index/status.rake
414
+ - lib/stretchy/rails/tasks/ml/delete.rake
415
+ - lib/stretchy/rails/tasks/ml/deploy.rake
416
+ - lib/stretchy/rails/tasks/ml/status.rake
417
+ - lib/stretchy/rails/tasks/pipeline/create.rake
418
+ - lib/stretchy/rails/tasks/pipeline/delete.rake
419
+ - lib/stretchy/rails/tasks/pipeline/status.rake
420
+ - lib/stretchy/rails/tasks/status.rake
421
+ - lib/stretchy/rails/tasks/stretchy.rake
327
422
  - lib/stretchy/record.rb
328
- - lib/stretchy/refreshable.rb
329
423
  - lib/stretchy/relation.rb
330
424
  - lib/stretchy/relations/aggregation_methods.rb
425
+ - lib/stretchy/relations/aggregation_methods/aggregation.rb
426
+ - lib/stretchy/relations/aggregation_methods/avg.rb
427
+ - lib/stretchy/relations/aggregation_methods/bucket_script.rb
428
+ - lib/stretchy/relations/aggregation_methods/bucket_selector.rb
429
+ - lib/stretchy/relations/aggregation_methods/bucket_sort.rb
430
+ - lib/stretchy/relations/aggregation_methods/cardinality.rb
431
+ - lib/stretchy/relations/aggregation_methods/children.rb
432
+ - lib/stretchy/relations/aggregation_methods/composite.rb
433
+ - lib/stretchy/relations/aggregation_methods/date_histogram.rb
434
+ - lib/stretchy/relations/aggregation_methods/date_range.rb
435
+ - lib/stretchy/relations/aggregation_methods/extended_stats.rb
436
+ - lib/stretchy/relations/aggregation_methods/filter.rb
437
+ - lib/stretchy/relations/aggregation_methods/filters.rb
438
+ - lib/stretchy/relations/aggregation_methods/geo_bounds.rb
439
+ - lib/stretchy/relations/aggregation_methods/geo_centroid.rb
440
+ - lib/stretchy/relations/aggregation_methods/global.rb
441
+ - lib/stretchy/relations/aggregation_methods/histogram.rb
442
+ - lib/stretchy/relations/aggregation_methods/ip_range.rb
443
+ - lib/stretchy/relations/aggregation_methods/max.rb
444
+ - lib/stretchy/relations/aggregation_methods/min.rb
445
+ - lib/stretchy/relations/aggregation_methods/missing.rb
446
+ - lib/stretchy/relations/aggregation_methods/nested.rb
447
+ - lib/stretchy/relations/aggregation_methods/percentile_ranks.rb
448
+ - lib/stretchy/relations/aggregation_methods/percentiles.rb
449
+ - lib/stretchy/relations/aggregation_methods/range.rb
450
+ - lib/stretchy/relations/aggregation_methods/reverse_nested.rb
451
+ - lib/stretchy/relations/aggregation_methods/sampler.rb
452
+ - lib/stretchy/relations/aggregation_methods/scripted_metric.rb
453
+ - lib/stretchy/relations/aggregation_methods/significant_terms.rb
454
+ - lib/stretchy/relations/aggregation_methods/stats.rb
455
+ - lib/stretchy/relations/aggregation_methods/sum.rb
456
+ - lib/stretchy/relations/aggregation_methods/terms.rb
457
+ - lib/stretchy/relations/aggregation_methods/top_hits.rb
458
+ - lib/stretchy/relations/aggregation_methods/top_metrics.rb
459
+ - lib/stretchy/relations/aggregation_methods/value_count.rb
460
+ - lib/stretchy/relations/aggregation_methods/weighted_avg.rb
331
461
  - lib/stretchy/relations/finder_methods.rb
332
462
  - lib/stretchy/relations/merger.rb
463
+ - lib/stretchy/relations/null_relation.rb
333
464
  - lib/stretchy/relations/query_builder.rb
334
465
  - lib/stretchy/relations/query_methods.rb
466
+ - lib/stretchy/relations/query_methods/bind.rb
467
+ - lib/stretchy/relations/query_methods/extending.rb
468
+ - lib/stretchy/relations/query_methods/fields.rb
469
+ - lib/stretchy/relations/query_methods/filter_query.rb
470
+ - lib/stretchy/relations/query_methods/has_field.rb
471
+ - lib/stretchy/relations/query_methods/highlight.rb
472
+ - lib/stretchy/relations/query_methods/hybrid.rb
473
+ - lib/stretchy/relations/query_methods/ids.rb
474
+ - lib/stretchy/relations/query_methods/match.rb
475
+ - lib/stretchy/relations/query_methods/must_not.rb
476
+ - lib/stretchy/relations/query_methods/neural.rb
477
+ - lib/stretchy/relations/query_methods/neural_sparse.rb
478
+ - lib/stretchy/relations/query_methods/none.rb
479
+ - lib/stretchy/relations/query_methods/or_filter.rb
480
+ - lib/stretchy/relations/query_methods/order.rb
481
+ - lib/stretchy/relations/query_methods/query_string.rb
482
+ - lib/stretchy/relations/query_methods/regexp.rb
483
+ - lib/stretchy/relations/query_methods/should.rb
484
+ - lib/stretchy/relations/query_methods/size.rb
485
+ - lib/stretchy/relations/query_methods/skip_callbacks.rb
486
+ - lib/stretchy/relations/query_methods/source.rb
487
+ - lib/stretchy/relations/query_methods/where.rb
488
+ - lib/stretchy/relations/scoping.rb
489
+ - lib/stretchy/relations/scoping/default.rb
490
+ - lib/stretchy/relations/scoping/named.rb
491
+ - lib/stretchy/relations/scoping/scope_registry.rb
335
492
  - lib/stretchy/relations/search_option_methods.rb
336
493
  - lib/stretchy/relations/spawn_methods.rb
337
494
  - lib/stretchy/repository.rb
338
- - lib/stretchy/scoping.rb
339
- - lib/stretchy/scoping/default.rb
340
- - lib/stretchy/scoping/named.rb
341
- - lib/stretchy/scoping/scope_registry.rb
342
495
  - lib/stretchy/shared_scopes.rb
343
496
  - lib/stretchy/utils.rb
344
497
  - lib/stretchy/version.rb
@@ -369,7 +522,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
369
522
  - !ruby/object:Gem::Version
370
523
  version: '0'
371
524
  requirements: []
372
- rubygems_version: 3.3.7
525
+ rubygems_version: 3.5.3
373
526
  signing_key:
374
527
  specification_version: 4
375
528
  summary: Rails ORM for Elasticsearch