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.
- checksums.yaml +4 -4
- data/.yardopts +2 -1
- data/README.md +28 -10
- data/Rakefile +56 -0
- data/docs/.nojekyll +0 -0
- data/docs/README.md +147 -0
- data/docs/_coverpage.md +14 -0
- data/docs/_sidebar.md +15 -0
- data/docs/examples/_sidebar.md +15 -0
- data/docs/examples/data_analysis.md +216 -0
- data/docs/examples/neural_search_with_llm.md +381 -0
- data/docs/examples/simple-ingest-pipeline.md +326 -0
- data/docs/guides/_sidebar.md +15 -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/connector/check_in.rb +64 -0
- data/lib/elasticsearch/api/actions/connector/delete.rb +64 -0
- data/lib/elasticsearch/api/actions/connector/get.rb +64 -0
- data/lib/elasticsearch/api/actions/connector/last_sync.rb +66 -0
- data/lib/elasticsearch/api/actions/connector/list.rb +60 -0
- data/lib/elasticsearch/api/actions/connector/post.rb +57 -0
- data/lib/elasticsearch/api/actions/connector/put.rb +66 -0
- data/lib/elasticsearch/api/actions/connector/update_api_key_id.rb +66 -0
- data/lib/elasticsearch/api/actions/connector/update_configuration.rb +66 -0
- data/lib/elasticsearch/api/actions/connector/update_error.rb +66 -0
- data/lib/elasticsearch/api/actions/connector/update_filtering.rb +66 -0
- data/lib/elasticsearch/api/actions/connector/update_index_name.rb +66 -0
- data/lib/elasticsearch/api/actions/connector/update_name.rb +66 -0
- data/lib/elasticsearch/api/actions/connector/update_native.rb +66 -0
- data/lib/elasticsearch/api/actions/connector/update_pipeline.rb +66 -0
- data/lib/elasticsearch/api/actions/connector/update_scheduling.rb +66 -0
- data/lib/elasticsearch/api/actions/connector/update_service_type.rb +66 -0
- data/lib/elasticsearch/api/actions/connector/update_status.rb +66 -0
- data/lib/elasticsearch/api/namespace/connector.rb +36 -0
- data/lib/opensearch/api/actions/machine_learning/connector/delete.rb +42 -0
- data/lib/opensearch/api/actions/machine_learning/connector/get.rb +42 -0
- data/lib/opensearch/api/actions/machine_learning/connector/list.rb +38 -0
- data/lib/opensearch/api/actions/machine_learning/connector/post.rb +35 -0
- data/lib/opensearch/api/actions/machine_learning/connector/put.rb +44 -0
- data/lib/opensearch/api/actions/machine_learning/models/predict.rb +32 -0
- data/lib/opensearch/api/namespace/connector.rb +19 -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 +28 -17
- 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 +16 -9
- 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 +29 -0
- data/lib/stretchy/delegation/gateway_delegation.rb +78 -0
- data/lib/stretchy/index_setting.rb +94 -0
- data/lib/stretchy/indexing/bulk.rb +75 -3
- data/lib/stretchy/machine_learning/connector.rb +130 -0
- data/lib/stretchy/machine_learning/errors.rb +25 -0
- data/lib/stretchy/machine_learning/model.rb +162 -109
- data/lib/stretchy/machine_learning/registry.rb +19 -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 +2 -0
- data/lib/stretchy/pipeline.rb +2 -1
- data/lib/stretchy/pipelines/processor.rb +40 -36
- data/lib/stretchy/querying.rb +7 -8
- data/lib/stretchy/rails/railtie.rb +11 -0
- data/lib/stretchy/rails/tasks/connector/create.rake +32 -0
- data/lib/stretchy/rails/tasks/connector/delete.rake +27 -0
- data/lib/stretchy/rails/tasks/connector/status.rake +31 -0
- data/lib/stretchy/rails/tasks/connector/update.rake +32 -0
- data/lib/stretchy/rails/tasks/index/create.rake +28 -0
- data/lib/stretchy/rails/tasks/index/delete.rake +27 -0
- data/lib/stretchy/rails/tasks/index/status.rake +23 -0
- data/lib/stretchy/rails/tasks/ml/delete.rake +25 -0
- data/lib/stretchy/rails/tasks/ml/deploy.rake +78 -0
- data/lib/stretchy/rails/tasks/ml/status.rake +31 -0
- data/lib/stretchy/rails/tasks/pipeline/create.rake +27 -0
- data/lib/stretchy/rails/tasks/pipeline/delete.rake +26 -0
- data/lib/stretchy/rails/tasks/pipeline/status.rake +25 -0
- data/lib/stretchy/rails/tasks/status.rake +15 -0
- data/lib/stretchy/rails/tasks/stretchy.rake +42 -0
- data/lib/stretchy/record.rb +5 -4
- data/lib/stretchy/relation.rb +229 -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 +82 -36
- 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 +48 -569
- 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/version.rb +1 -1
- data/lib/stretchy.rb +24 -10
- metadata +170 -17
- data/lib/stretchy/common.rb +0 -38
- 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,40 @@
|
|
1
|
+
module Stretchy
|
2
|
+
module Relations
|
3
|
+
module QueryMethods
|
4
|
+
module Ids
|
5
|
+
|
6
|
+
# Filters documents that only have the provided ids.
|
7
|
+
#
|
8
|
+
# This method is used to filter the results of a query based on document ids. It accepts an array of ids.
|
9
|
+
#
|
10
|
+
# ### Parameters
|
11
|
+
#
|
12
|
+
# - `args:` The Array of ids to be matched by the query.
|
13
|
+
#
|
14
|
+
# ### Returns
|
15
|
+
# Returns a new Stretchy::Relation with the specified ids to be matched.
|
16
|
+
#
|
17
|
+
# ---
|
18
|
+
#
|
19
|
+
# ### Examples
|
20
|
+
#
|
21
|
+
# #### Filter by ids
|
22
|
+
#
|
23
|
+
# ```ruby
|
24
|
+
# Model.ids([1, 2, 3])
|
25
|
+
# ```
|
26
|
+
#
|
27
|
+
def ids(*args)
|
28
|
+
spawn.ids!(*args)
|
29
|
+
end
|
30
|
+
|
31
|
+
def ids!(*args) # :nodoc:
|
32
|
+
self.ids_values += args
|
33
|
+
self
|
34
|
+
end
|
35
|
+
|
36
|
+
QueryMethods.register!(:ids)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module Stretchy
|
2
|
+
module Relations
|
3
|
+
module QueryMethods
|
4
|
+
module Match
|
5
|
+
|
6
|
+
# This method is used to add conditions to the query.
|
7
|
+
#
|
8
|
+
# ### Parameters
|
9
|
+
#
|
10
|
+
# - `query:` (Required) - Text, number, boolean value or date you wish to find in the provided field. The match query analyzes any provided text before performing a search. This means the match query can search text fields for analyzed tokens rather than an exact term.
|
11
|
+
# - `options:` (Optional) - A hash of options to customize the match query. Options include:
|
12
|
+
# - `analyzer:` (string) - Analyzer used to convert the text in the query value into tokens. Defaults to the index-time analyzer mapped for the field. If no analyzer is mapped, the index’s default analyzer is used.
|
13
|
+
# - `auto_generate_synonyms_phrase_query:` (Boolean) - If true, match phrase queries are automatically created for multi-term synonyms. Defaults to true.
|
14
|
+
# - `boost:` (float) - Floating point number used to decrease or increase the relevance scores of the query. Defaults to 1.0.
|
15
|
+
# - `fuzziness:` (string) - Maximum edit distance allowed for matching.
|
16
|
+
# - `max_expansions:` (integer) - Maximum number of terms to which the query will expand. Defaults to 50.
|
17
|
+
# - `prefix_length:` (integer) - Number of beginning characters left unchanged for fuzzy matching. Defaults to 0.
|
18
|
+
# - `fuzzy_transpositions:` (Boolean) - If true, edits for fuzzy matching include transpositions of two adjacent characters (ab → ba). Defaults to true.
|
19
|
+
# - `fuzzy_rewrite:` (string) - Method used to rewrite the query.
|
20
|
+
# - `lenient:` (Boolean) - If true, format-based errors, such as providing a text query value for a numeric field, are ignored. Defaults to false.
|
21
|
+
# - `operator:` (string) - Boolean logic used to interpret text in the query value. Valid values are: OR (Default), AND.
|
22
|
+
# - `minimum_should_match:` (string) - Minimum number of clauses that must match for a document to be returned.
|
23
|
+
# - `zero_terms_query:` (string) - Indicates whether no documents are returned if the analyzer removes all tokens, such as when using a stop filter. Valid values are: none (Default), all.
|
24
|
+
#
|
25
|
+
# ### Returns
|
26
|
+
#
|
27
|
+
# Returns a Stretchy::Relation with the specified conditions applied.
|
28
|
+
#
|
29
|
+
# ### Examples
|
30
|
+
#
|
31
|
+
# ```ruby
|
32
|
+
# Model.match(path: "/new/things")
|
33
|
+
# ```
|
34
|
+
#
|
35
|
+
def match(opts = :chain, *rest)
|
36
|
+
return MatchChain.new(spawn) if opts == :chain
|
37
|
+
return self if opts.blank?
|
38
|
+
|
39
|
+
spawn.match!(opts, *rest)
|
40
|
+
end
|
41
|
+
|
42
|
+
def match!(opts, *rest) # :nodoc:
|
43
|
+
self.match_values = [Hash[*opts.shift], **opts]
|
44
|
+
self
|
45
|
+
end
|
46
|
+
|
47
|
+
QueryMethods.register!(:match)
|
48
|
+
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module Stretchy
|
2
|
+
module Relations
|
3
|
+
module QueryMethods
|
4
|
+
module MustNot
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
# Adds negated conditions to the query.
|
7
|
+
#
|
8
|
+
# Each argument is a keyword where the key is the attribute name and the value is the value to exclude.
|
9
|
+
# This method acts as a convenience method for adding negated conditions to the query. It can also be used to add
|
10
|
+
# range, regex, terms, and id queries through shorthand parameters.
|
11
|
+
#
|
12
|
+
# ### Parameters:
|
13
|
+
# - `opts:` The keywords containing attribute-value pairs for conditions.
|
14
|
+
#
|
15
|
+
# ### Returns
|
16
|
+
# Returns a new Stretchy::Relation with the specified conditions excluded.
|
17
|
+
#
|
18
|
+
# ---
|
19
|
+
#
|
20
|
+
# ### Examples
|
21
|
+
#
|
22
|
+
# #### Exclude multiple conditions
|
23
|
+
# ```ruby
|
24
|
+
# Model.must_not(color: 'blue', size: :large)
|
25
|
+
# ```
|
26
|
+
#
|
27
|
+
def must_not(opts = :chain, *rest)
|
28
|
+
if opts == :chain
|
29
|
+
WhereChain.new(spawn)
|
30
|
+
elsif opts.blank?
|
31
|
+
self
|
32
|
+
else
|
33
|
+
spawn.must_not!(opts, *rest)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
def must_not!(opts, *rest) # :nodoc:
|
39
|
+
if opts == :chain
|
40
|
+
WhereChain.new(self)
|
41
|
+
else
|
42
|
+
self.must_not_values += build_where(opts, rest)
|
43
|
+
self
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
# Alias for {#must_not}
|
48
|
+
# @see #must_not
|
49
|
+
alias :where_not :must_not
|
50
|
+
QueryMethods.register!(:where_not, :must_not)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module Stretchy
|
2
|
+
module Relations
|
3
|
+
module QueryMethods
|
4
|
+
module Neural
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
# Perform a neural search on a specific field.
|
7
|
+
#
|
8
|
+
# The `neural` method accepts a Hash with the field name as the key and the query text as the value.
|
9
|
+
# It can also accept a Hash with `query_text` and `query_image` keys for multimodal neural search.
|
10
|
+
#
|
11
|
+
# ### Parameters
|
12
|
+
#
|
13
|
+
# - `opts:` The Hash options used to refine the selection (default: {}):
|
14
|
+
# - `:field:` The Symbol or String representing the field name.
|
15
|
+
# - `:query_text:` The String representing the query text (optional).
|
16
|
+
# - `:query_image:` The String representing the base-64 encoded query image (optional).
|
17
|
+
# - `:model_id:` The String representing the ID of the model to be used (required if default model ID is not set).
|
18
|
+
# - `:k:` The Integer representing the number of results to return (optional, default: 10).
|
19
|
+
# - `:filter:` The Object representing a query to reduce the number of documents considered (optional).
|
20
|
+
#
|
21
|
+
# ### Returns
|
22
|
+
# Returns a new Stretchy::Relation with the neural search applied.
|
23
|
+
#
|
24
|
+
# ---
|
25
|
+
#
|
26
|
+
# ### Examples
|
27
|
+
#
|
28
|
+
# #### Neural search
|
29
|
+
#
|
30
|
+
# ```ruby
|
31
|
+
# Model.neural(body_embeddings: 'hello world', model_id: '1234')
|
32
|
+
# ```
|
33
|
+
#
|
34
|
+
# #### Multimodal neural search
|
35
|
+
#
|
36
|
+
# ```ruby
|
37
|
+
# Model.neural(body_embeddings: {
|
38
|
+
# query_text: 'hello world',
|
39
|
+
# query_image: 'base64encodedimage'
|
40
|
+
# },
|
41
|
+
# model_id: '1234'
|
42
|
+
# )
|
43
|
+
# ```
|
44
|
+
#
|
45
|
+
def neural(opts)
|
46
|
+
spawn.neural!(opts)
|
47
|
+
end
|
48
|
+
|
49
|
+
def neural!(opts) # :nodoc:
|
50
|
+
self.neural_values += [opts]
|
51
|
+
self
|
52
|
+
end
|
53
|
+
|
54
|
+
QueryMethods.register!(:neural)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module Stretchy
|
2
|
+
module Relations
|
3
|
+
module QueryMethods
|
4
|
+
module NeuralSparse
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
# Perform a neural sparse search on a specific field.
|
7
|
+
#
|
8
|
+
# The `neural_sparse` method accepts a Hash with the `field_name`, `model_id`, and `max_token_score` keys.
|
9
|
+
#
|
10
|
+
# ### Parameters
|
11
|
+
#
|
12
|
+
# - `opts:` The Hash options used to refine the selection (default: {}):
|
13
|
+
# - `:field_name:` The keyword argument representing the passage to be embedded and the value to be searched.
|
14
|
+
# - `:model_id:` The String representing the ID of the model to be used.
|
15
|
+
# - `:max_token_score:` The Integer representing the maximum token score to consider.
|
16
|
+
#
|
17
|
+
# ### Returns
|
18
|
+
# Returns a new Stretchy::Relation with the neural sparse search applied.
|
19
|
+
#
|
20
|
+
# ---
|
21
|
+
#
|
22
|
+
# ### Examples
|
23
|
+
#
|
24
|
+
# #### Neural sparse search
|
25
|
+
#
|
26
|
+
# ```ruby
|
27
|
+
# Model.neural_sparse(passage_embedding: 'hello world', model_id: '1234', max_token_score: 2)
|
28
|
+
# ```
|
29
|
+
#
|
30
|
+
def neural_sparse(opts)
|
31
|
+
spawn.neural_sparse!(opts)
|
32
|
+
end
|
33
|
+
|
34
|
+
def neural_sparse!(opts) # :nodoc:
|
35
|
+
self.neural_sparse_values += [opts]
|
36
|
+
self
|
37
|
+
end
|
38
|
+
|
39
|
+
QueryMethods.register!(:neural_sparse)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Stretchy
|
2
|
+
module Relations
|
3
|
+
module QueryMethods
|
4
|
+
module None
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
# Returns a chainable relation with zero records.
|
8
|
+
def none
|
9
|
+
extending(Stretchy::Relations::NullRelation)
|
10
|
+
end
|
11
|
+
|
12
|
+
def none! # :nodoc:
|
13
|
+
extending!(Stretchy::Relations::NullRelation)
|
14
|
+
end
|
15
|
+
|
16
|
+
QueryMethods.register!(:none)
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Stretchy
|
2
|
+
module Relations
|
3
|
+
module QueryMethods
|
4
|
+
module OrFilter
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
# @deprecated in elasticsearch 7.x+ use {#filter_query} instead
|
7
|
+
def or_filter(name, options = {}, &block)
|
8
|
+
spawn.or_filter!(name, options, &block)
|
9
|
+
end
|
10
|
+
|
11
|
+
def or_filter!(name, options = {}, &block) # :nodoc:
|
12
|
+
self.or_filter_values += [{name: name, args: options}]
|
13
|
+
self
|
14
|
+
end
|
15
|
+
|
16
|
+
QueryMethods.register!(:or_filter)
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
module Stretchy
|
2
|
+
module Relations
|
3
|
+
module QueryMethods
|
4
|
+
module Order
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
# Allows you to add one or more sorts on specified fields.
|
7
|
+
#
|
8
|
+
# This method is used to sort the results of a query based on one or more fields. It accepts a variable number of arguments,
|
9
|
+
# each of which is a hash where the key is the field name and the value is the sort direction or a hash of sort options.
|
10
|
+
#
|
11
|
+
# ### Parameters
|
12
|
+
#
|
13
|
+
# - `args:` The Array of hashes representing the sort fields and directions or options (default: []).
|
14
|
+
# - `:attribute:` The Symbol or String representing the field name.
|
15
|
+
# - `:direction:` The Symbol representing the sort direction (:asc or :desc).
|
16
|
+
# - `:options:` The Hash representing the sort options (optional).
|
17
|
+
# - `:order:` The Symbol representing the sort direction (:asc or :desc).
|
18
|
+
# - `:mode:` The Symbol representing the sort mode (:avg, :min, :max, :sum, :median).
|
19
|
+
# - `:numeric_type:` The Symbol representing the numeric type (:double, :long, :date, :date_nanos).
|
20
|
+
# - `:missing:` The value to use for documents without the field.
|
21
|
+
# - `:nested:` The Hash representing the nested sort options.
|
22
|
+
# - `:path:` The String representing the path to the nested object.
|
23
|
+
# - `:filter:` The Hash representing the filter to apply to the nested object.
|
24
|
+
# - `:max_children:` The Integer representing the maximum number of children to consider per root document when picking the sort value.
|
25
|
+
#
|
26
|
+
# ### Returns
|
27
|
+
# Returns a new Stretchy::Relation with the specified order.
|
28
|
+
#
|
29
|
+
# ---
|
30
|
+
#
|
31
|
+
# ### Examples
|
32
|
+
#
|
33
|
+
# #### Single field
|
34
|
+
#
|
35
|
+
# ```ruby
|
36
|
+
# Model.order(created_at: :asc)
|
37
|
+
# ```
|
38
|
+
#
|
39
|
+
# #### Multiple fields
|
40
|
+
#
|
41
|
+
# ```ruby
|
42
|
+
# Model.order(age: :desc, name: :asc, price: {order: :desc, mode: :avg})
|
43
|
+
# ```
|
44
|
+
#
|
45
|
+
def order(*args)
|
46
|
+
check_if_method_has_arguments!(:order, args)
|
47
|
+
spawn.order!(*args)
|
48
|
+
end
|
49
|
+
|
50
|
+
def order!(*args) # :nodoc:
|
51
|
+
self.order_values += args.first.zip.map(&:to_h)
|
52
|
+
self
|
53
|
+
end
|
54
|
+
|
55
|
+
# Alias for {#order}
|
56
|
+
# @see #order
|
57
|
+
alias :sort :order
|
58
|
+
QueryMethods.register!(:sort, :order)
|
59
|
+
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module Stretchy
|
2
|
+
module Relations
|
3
|
+
module QueryMethods
|
4
|
+
module QueryString
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
# Adds a query string to the search.
|
7
|
+
#
|
8
|
+
# The query string uses Elasticsearch's Query String Query syntax, which includes a series of terms and operators.
|
9
|
+
# Terms can be single words or phrases. Operators include AND, OR, and NOT, among others.
|
10
|
+
# Field names can be included in the query string to search for specific values in specific fields. (e.g. "eye_color: green")
|
11
|
+
# The default operator between terms are treated as OR operators.
|
12
|
+
#
|
13
|
+
# ### Parameters
|
14
|
+
#
|
15
|
+
# - `opts:` The query string
|
16
|
+
#
|
17
|
+
# ### Returns
|
18
|
+
# Returns a new Stretchy::Relation, which reflects the query string.
|
19
|
+
#
|
20
|
+
# ---
|
21
|
+
#
|
22
|
+
# ### Examples
|
23
|
+
#
|
24
|
+
# #### Query string
|
25
|
+
#
|
26
|
+
# ```ruby
|
27
|
+
# Model.query_string("((big cat) OR (domestic cat)) AND NOT panther eye_color: green")
|
28
|
+
# ```
|
29
|
+
#
|
30
|
+
def query_string(opts = :chain, *rest)
|
31
|
+
spawn.query_string!(opts, *rest)
|
32
|
+
end
|
33
|
+
|
34
|
+
def query_string!(opts, *rest) # :nodoc:
|
35
|
+
self.query_string_values += build_where(opts, rest)
|
36
|
+
self
|
37
|
+
end
|
38
|
+
|
39
|
+
QueryMethods.register!(:query_string)
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
module Stretchy
|
2
|
+
module Relations
|
3
|
+
module QueryMethods
|
4
|
+
module Regexp
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
# Adds a regexp condition to the query.
|
7
|
+
#
|
8
|
+
# This method is used to filter the results of a query based on a regular expression. It accepts a hash where the key is the field name and the value is the regular expression.
|
9
|
+
#
|
10
|
+
# ### Parameters
|
11
|
+
#
|
12
|
+
# - `field:` The Symbol or String representing the field name as the key and the regular expression to be matched as value.
|
13
|
+
# - `opts:` The keywords representing additional options for the regexp query (optional).
|
14
|
+
# - `flags:` The String representing the flags to use for the regexp query (e.g. 'ALL').
|
15
|
+
# - `use_keyword:` The Boolean indicating whether to use the .keyword field for the regexp query (default: true).
|
16
|
+
# - `case_insensitive:` The Boolean indicating whether to use case insensitive matching. If the regexp has ignore case flag `/regex/i`, this is automatically set to true.
|
17
|
+
# - `max_determinized_states:` The Integer representing the maximum number of states that the regexp query can produce.
|
18
|
+
# - `rewrite:` The String representing the rewrite method to use for the regexp query.
|
19
|
+
#
|
20
|
+
# ### Returns
|
21
|
+
# Returns a new Stretchy::Relation, which reflects the regexp condition.
|
22
|
+
#
|
23
|
+
# ---
|
24
|
+
#
|
25
|
+
# ### Examples
|
26
|
+
#
|
27
|
+
# #### Regexp condition
|
28
|
+
#
|
29
|
+
# ```ruby
|
30
|
+
# Model.regexp(name: /john|jane/)
|
31
|
+
#```
|
32
|
+
#
|
33
|
+
# #### Regexp with case insensitive matching
|
34
|
+
# ```ruby
|
35
|
+
# Model.regexp(name: /john|jane/i)
|
36
|
+
# ```
|
37
|
+
#
|
38
|
+
# #### Regexp with flags
|
39
|
+
# ```ruby
|
40
|
+
# Model.regexp(name: /john|jane/i, flags: 'ALL')
|
41
|
+
# ```
|
42
|
+
#
|
43
|
+
def regexp(args)
|
44
|
+
spawn.regexp!(args)
|
45
|
+
end
|
46
|
+
|
47
|
+
def regexp!(args) # :nodoc:
|
48
|
+
args = args.to_a
|
49
|
+
target_field, regex = args.shift
|
50
|
+
opts = args.to_h
|
51
|
+
opts.merge!(case_insensitive: true) if regex.casefold?
|
52
|
+
self.regexp_values += [[Hash[target_field, regex.source], opts]]
|
53
|
+
self
|
54
|
+
end
|
55
|
+
|
56
|
+
QueryMethods.register!(:regexp)
|
57
|
+
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module Stretchy
|
2
|
+
module Relations
|
3
|
+
module QueryMethods
|
4
|
+
module Should
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
# Adds optional conditions to the query.
|
7
|
+
#
|
8
|
+
# Each argument is a hash where the key is the attribute to filter by and the value is the value to match optionally.
|
9
|
+
#
|
10
|
+
# ### Parameters
|
11
|
+
#
|
12
|
+
# - `opts:` The Hash representing the attribute-value pairs to match optionally or a Symbol `:chain` to return a new WhereChain.
|
13
|
+
#
|
14
|
+
# ### Returns
|
15
|
+
# Returns a new Stretchy::Relation, which reflects the optional conditions.
|
16
|
+
#
|
17
|
+
# ---
|
18
|
+
#
|
19
|
+
# ### Examples
|
20
|
+
#
|
21
|
+
# #### Optional conditions
|
22
|
+
#
|
23
|
+
# ```ruby
|
24
|
+
# Model.should(color: :pink, size: :medium)
|
25
|
+
# ```
|
26
|
+
#
|
27
|
+
def should(opts = :chain, *rest)
|
28
|
+
if opts == :chain
|
29
|
+
WhereChain.new(spawn)
|
30
|
+
elsif opts.blank?
|
31
|
+
self
|
32
|
+
else
|
33
|
+
spawn.should!(opts, *rest)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def should!(opts, *rest) # :nodoc:
|
38
|
+
if opts == :chain
|
39
|
+
WhereChain.new(self)
|
40
|
+
else
|
41
|
+
self.should_values += build_where(opts, rest)
|
42
|
+
self
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
QueryMethods.register!(:should)
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module Stretchy
|
2
|
+
module Relations
|
3
|
+
module QueryMethods
|
4
|
+
module Size
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
# Sets the maximum number of records to be retrieved.
|
7
|
+
#
|
8
|
+
# This method is used to limit the number of records returned by the query. It accepts an integer as an argument.
|
9
|
+
#
|
10
|
+
# ### Parameters
|
11
|
+
#
|
12
|
+
# - `args:` The Integer representing the maximum number of records to retrieve.
|
13
|
+
#
|
14
|
+
# ### Returns
|
15
|
+
# Returns a new Stretchy::Relation, which reflects the limit.
|
16
|
+
#
|
17
|
+
# ---
|
18
|
+
#
|
19
|
+
# ### Examples
|
20
|
+
#
|
21
|
+
# #### Limit the number of records
|
22
|
+
#
|
23
|
+
# ```ruby
|
24
|
+
# Model.size(10)
|
25
|
+
# ```
|
26
|
+
#
|
27
|
+
def size(args)
|
28
|
+
spawn.size!(args)
|
29
|
+
end
|
30
|
+
|
31
|
+
def size!(args) # :nodoc:
|
32
|
+
self.size_value = args
|
33
|
+
self
|
34
|
+
end
|
35
|
+
|
36
|
+
# Alias for {#size}
|
37
|
+
# @see #size
|
38
|
+
alias :limit :size
|
39
|
+
|
40
|
+
QueryMethods.register!(:limit, :size)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module Stretchy
|
2
|
+
module Relations
|
3
|
+
module QueryMethods
|
4
|
+
module SkipCallbacks
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
# Allows you to skip callbacks for the specified fields.
|
7
|
+
#
|
8
|
+
# This method is used to skip callbacks that are added by `query_must_have` for the specified fields for the current query. It accepts a variable number of arguments, each of which is the name of a field to skip callbacks for.
|
9
|
+
#
|
10
|
+
# ### Parameters
|
11
|
+
#
|
12
|
+
# - `args:` The Array of field names to skip callbacks for.
|
13
|
+
#
|
14
|
+
# ### Returns
|
15
|
+
# Returns a new Stretchy::Relation with the specified fields to skip callbacks for.
|
16
|
+
#
|
17
|
+
# ---
|
18
|
+
#
|
19
|
+
# ### Examples
|
20
|
+
#
|
21
|
+
# #### Skip callbacks for a single field
|
22
|
+
#
|
23
|
+
# ```ruby
|
24
|
+
# Model.skip_callbacks(:routing)
|
25
|
+
# ```
|
26
|
+
#
|
27
|
+
# #### Skip callbacks for multiple fields
|
28
|
+
#
|
29
|
+
# ```ruby
|
30
|
+
# Model.skip_callbacks(:routing, :relevance)
|
31
|
+
# ```
|
32
|
+
#
|
33
|
+
def skip_callbacks(*args)
|
34
|
+
spawn.skip_callbacks!(*args)
|
35
|
+
end
|
36
|
+
|
37
|
+
def skip_callbacks!(*args) # :nodoc:
|
38
|
+
self.skip_callbacks_values += args
|
39
|
+
self
|
40
|
+
end
|
41
|
+
|
42
|
+
QueryMethods.register!(:skip_callbacks)
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
module Stretchy
|
2
|
+
module Relations
|
3
|
+
module QueryMethods
|
4
|
+
module Source
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
# Controls which fields of the source are returned.
|
8
|
+
#
|
9
|
+
# This method supports source filtering, which allows you to include or exclude fields from the source.
|
10
|
+
# You can specify fields directly, use wildcard patterns, or use an object containing arrays
|
11
|
+
# of includes and excludes patterns.
|
12
|
+
#
|
13
|
+
# If the includes property is specified, only source fields that match one of its patterns are returned.
|
14
|
+
# You can exclude fields from this subset using the excludes property.
|
15
|
+
#
|
16
|
+
# If the includes property is not specified, the entire document source is returned, excluding any
|
17
|
+
# fields that match a pattern in the excludes property.
|
18
|
+
#
|
19
|
+
# ### Parameters
|
20
|
+
# - `:includes:` The Array of fields to be included in the source (default: []).
|
21
|
+
# - `:excludes:` The Array of fields to be excluded from the source (default: []).
|
22
|
+
# - Or a Boolean indicating whether to include the source.
|
23
|
+
#
|
24
|
+
# ### Returns
|
25
|
+
# Returns a Stretchy::Relation, which reflects the source filtering.
|
26
|
+
#
|
27
|
+
# ---
|
28
|
+
#
|
29
|
+
# ### Examples
|
30
|
+
#
|
31
|
+
# #### Include source
|
32
|
+
# ```ruby
|
33
|
+
# Model.source(includes: [:name, :email])
|
34
|
+
# ```
|
35
|
+
#
|
36
|
+
# #### Exclude source
|
37
|
+
# ```ruby
|
38
|
+
# Model.source(excludes: [:name, :email])
|
39
|
+
# ```
|
40
|
+
#
|
41
|
+
# #### No source
|
42
|
+
# ```ruby
|
43
|
+
# Model.source(false) # don't include source
|
44
|
+
# ```
|
45
|
+
#
|
46
|
+
def source(*args)
|
47
|
+
spawn.source!(*args)
|
48
|
+
end
|
49
|
+
|
50
|
+
def source!(*args) # :nodoc:
|
51
|
+
self.source_values += args
|
52
|
+
self
|
53
|
+
end
|
54
|
+
|
55
|
+
QueryMethods.register!(:source)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|