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
@@ -1,24 +1,41 @@
|
|
1
1
|
module Stretchy::Attributes::Type
|
2
|
-
#
|
2
|
+
# The RankFeatures attribute type
|
3
3
|
#
|
4
|
-
#
|
5
|
-
|
6
|
-
#
|
7
|
-
#
|
8
|
-
#
|
4
|
+
# This class is used to define a rank_features attribute for a model. It provides support for the Elasticsearch rank_features data type, which is a type of data type that can index numeric feature vectors, so that they can later be used to boost documents in queries with a rank_feature query. It is better suited when the list of features is sparse so that it wouldn’t be reasonable to add one field to the mappings for each of them.
|
5
|
+
#
|
6
|
+
# ### Parameters
|
7
|
+
#
|
8
|
+
# - `type:` `:rank_features`.
|
9
|
+
# - `options:` The Hash of options for the attribute.
|
10
|
+
# - `:positive_score_impact:` The Boolean indicating if features correlate positively with the score. If set to false, the score decreases with the value of the feature instead of increasing. Defaults to true.
|
11
|
+
#
|
12
|
+
# ---
|
13
|
+
#
|
14
|
+
# ### Examples
|
9
15
|
#
|
10
|
-
#
|
16
|
+
# #### Define a rank_features attribute
|
11
17
|
#
|
12
|
-
#
|
18
|
+
# ```ruby
|
19
|
+
# class MyModel < StretchyModel
|
13
20
|
# attribute :negative_reviews, :rank_features, positive_score_impact: false
|
14
21
|
# end
|
22
|
+
# ```
|
15
23
|
#
|
16
|
-
|
17
|
-
class RankFeatures < Stretchy::Attributes::Type::Base
|
24
|
+
class RankFeatures < Stretchy::Attributes::Type::Hash
|
18
25
|
OPTIONS = [:positive_score_impact]
|
19
26
|
|
27
|
+
def mappings(name)
|
28
|
+
options = {type: type}
|
29
|
+
OPTIONS.each { |option| options[option] = send(option) unless send(option).nil? }
|
30
|
+
{ name => options }.as_json
|
31
|
+
end
|
32
|
+
|
20
33
|
def type
|
21
34
|
:rank_features
|
22
35
|
end
|
36
|
+
|
37
|
+
def type_for_database
|
38
|
+
:rank_features
|
39
|
+
end
|
23
40
|
end
|
24
41
|
end
|
@@ -1,25 +1,35 @@
|
|
1
1
|
module Stretchy::Attributes::Type
|
2
|
-
#
|
3
|
-
#
|
4
|
-
#
|
5
|
-
#
|
6
|
-
#
|
7
|
-
#
|
8
|
-
#
|
9
|
-
#
|
10
|
-
#
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
#
|
15
|
-
#
|
16
|
-
#
|
17
|
-
#
|
18
|
-
#
|
2
|
+
# The SearchAsYouType attribute type
|
3
|
+
#
|
4
|
+
# This class is used to define a search_as_you_type attribute for a model. This field type is optimized to provide out-of-the-box support for queries that serve an as-you-type completion use case.
|
5
|
+
#
|
6
|
+
# ### Parameters
|
7
|
+
#
|
8
|
+
# - `type:` `:search_as_you_type`.
|
9
|
+
# - `options:` The Hash of options for the attribute.
|
10
|
+
# - `:max_shingle_size:` The Integer indicating the largest shingle size to create. Valid values are 2 to 4. Defaults to 3.
|
11
|
+
# - `:analyzer:` The String analyzer to be used for text fields, both at index-time and at search-time. Defaults to the default index analyzer, or the standard analyzer.
|
12
|
+
# - `:index:` The Boolean indicating if the field should be searchable. Defaults to true.
|
13
|
+
# - `:index_options:` The String indicating what information should be stored in the index, for search and highlighting purposes. Defaults to 'positions'.
|
14
|
+
# - `:norms:` The Boolean indicating if field-length should be taken into account when scoring queries. Defaults to true.
|
15
|
+
# - `:store:` The Boolean indicating if the field value should be stored and retrievable separately from the _source field. Defaults to false.
|
16
|
+
# - `:search_analyzer:` The String analyzer that should be used at search time on text fields. Defaults to the analyzer setting.
|
17
|
+
# - `:search_quote_analyzer:` The String analyzer that should be used at search time when a phrase is encountered. Defaults to the search_analyzer setting.
|
18
|
+
# - `:similarity:` The String indicating which scoring algorithm or similarity should be used. Defaults to 'BM25'.
|
19
|
+
# - `:term_vector:` The String indicating if term vectors should be stored for the field. Defaults to 'no'.
|
20
|
+
#
|
21
|
+
# ---
|
22
|
+
#
|
23
|
+
# ### Examples
|
24
|
+
#
|
25
|
+
# #### Define a search_as_you_type attribute
|
26
|
+
#
|
27
|
+
# ```ruby
|
28
|
+
# class MyModel < StretchyModel
|
19
29
|
# attribute :name, :search_as_you_type, max_shingle_size: 4
|
20
30
|
# end
|
31
|
+
# ```
|
21
32
|
#
|
22
|
-
# Returns nothing.
|
23
33
|
class SearchAsYouType < Stretchy::Attributes::Type::Base
|
24
34
|
OPTIONS = [:max_shingle_size, :analyzer, :index, :index_options, :norms, :store, :search_analyzer, :search_quote_analyzer, :similarity, :term_vector]
|
25
35
|
|
@@ -1,19 +1,29 @@
|
|
1
1
|
module Stretchy::Attributes::Type
|
2
|
-
#
|
2
|
+
# The Shape attribute type
|
3
3
|
#
|
4
|
-
#
|
5
|
-
# :orientation - The String indicating how to interpret vertex order for polygons / multipolygons. Can be 'right', 'ccw', 'counterclockwise', 'left', 'cw', 'clockwise'. Defaults to 'ccw'.
|
6
|
-
# :ignore_malformed - The Boolean indicating if malformed GeoJSON or WKT shapes should be ignored. Defaults to false.
|
7
|
-
# :ignore_z_value - The Boolean indicating if the z value of three dimension points should be ignored. Defaults to true.
|
8
|
-
# :coerce - The Boolean indicating if unclosed linear rings in polygons will be automatically closed. Defaults to false.
|
4
|
+
# This class is used to define a shape attribute for a model. It provides support for the Elasticsearch shape data type, which is a type of data type that can hold complex shapes represented as GeoJSON or WKT.
|
9
5
|
#
|
10
|
-
#
|
6
|
+
# ### Parameters
|
11
7
|
#
|
12
|
-
#
|
8
|
+
# - `type:` `:shape`.
|
9
|
+
# - `options:` The Hash of options for the attribute.
|
10
|
+
# - `:orientation:` The String indicating how to interpret vertex order for polygons / multipolygons. Can be 'right', 'ccw', 'counterclockwise', 'left', 'cw', 'clockwise'. Defaults to 'ccw'.
|
11
|
+
# - `:ignore_malformed:` The Boolean indicating if malformed GeoJSON or WKT shapes should be ignored. Defaults to false.
|
12
|
+
# - `:ignore_z_value:` The Boolean indicating if the z value of three dimension points should be ignored. Defaults to true.
|
13
|
+
# - `:coerce:` The Boolean indicating if unclosed linear rings in polygons will be automatically closed. Defaults to false.
|
14
|
+
#
|
15
|
+
# ---
|
16
|
+
#
|
17
|
+
# ### Examples
|
18
|
+
#
|
19
|
+
# #### Define a shape attribute
|
20
|
+
#
|
21
|
+
# ```ruby
|
22
|
+
# class MyModel < StretchyModel
|
13
23
|
# attribute :boundary, :shape, orientation: 'cw'
|
14
24
|
# end
|
25
|
+
# ```
|
15
26
|
#
|
16
|
-
# Returns nothing.
|
17
27
|
class Shape < Stretchy::Attributes::Type::Base
|
18
28
|
OPTIONS = [:orientation, :ignore_malformed, :ignore_z_value, :coerce]
|
19
29
|
|
@@ -1,21 +1,27 @@
|
|
1
|
-
#
|
2
|
-
# attribute :ml, :sparse_vector
|
3
|
-
#
|
4
|
-
# {
|
5
|
-
# "mappings": {
|
6
|
-
# "properties": {
|
7
|
-
# "ml.tokens": {
|
8
|
-
# "type": "sparse_vector"
|
9
|
-
# }
|
10
|
-
# }
|
11
|
-
# }
|
12
|
-
# }
|
13
|
-
#
|
14
|
-
|
15
|
-
|
16
1
|
module Stretchy
|
17
2
|
module Attributes
|
18
3
|
module Type
|
4
|
+
# The SparseVector attribute type
|
5
|
+
#
|
6
|
+
# This class is used to define a sparse_vector attribute for a model. It provides support for the Elasticsearch sparse_vector data type, which is a type of data type that can hold sparse vectors of float values.
|
7
|
+
#
|
8
|
+
# ### Parameters
|
9
|
+
#
|
10
|
+
# - `type:` `:sparse_vector`.
|
11
|
+
# - `options:` The Hash of options for the attribute. This type does not have any specific options.
|
12
|
+
#
|
13
|
+
# ---
|
14
|
+
#
|
15
|
+
# ### Examples
|
16
|
+
#
|
17
|
+
# #### Define a sparse_vector attribute
|
18
|
+
#
|
19
|
+
# ```ruby
|
20
|
+
# class MyModel < StretchyModel
|
21
|
+
# attribute :ml, :sparse_vector
|
22
|
+
# end
|
23
|
+
# ```
|
24
|
+
#
|
19
25
|
class SparseVector < Stretchy::Attributes::Type::Base
|
20
26
|
|
21
27
|
def type
|
@@ -23,12 +29,10 @@ module Stretchy
|
|
23
29
|
end
|
24
30
|
|
25
31
|
def mappings(name)
|
26
|
-
|
27
|
-
|
28
|
-
"
|
29
|
-
|
30
|
-
}
|
31
|
-
}
|
32
|
+
{
|
33
|
+
"#{name}.tokens": {
|
34
|
+
type: "sparse_vector"
|
35
|
+
}
|
32
36
|
}.as_json
|
33
37
|
end
|
34
38
|
end
|
@@ -1,5 +1,46 @@
|
|
1
1
|
module Stretchy::Attributes::Type
|
2
|
-
|
2
|
+
# The String attribute type
|
3
|
+
#
|
4
|
+
# _alias for `:text`_
|
5
|
+
#
|
6
|
+
# This class is used to define a string attribute for a model. It provides support for the Elasticsearch text data type, which is a type of data type that can hold text. In this library, the string type is an alias for the text type.
|
7
|
+
#
|
8
|
+
# ### Parameters
|
9
|
+
#
|
10
|
+
# - `type:` `:string`.
|
11
|
+
# - `options:` The Hash of options for the attribute.
|
12
|
+
# - `:analyzer:` The String analyzer to be used for the text field, both at index-time and at search-time. Defaults to the default index analyzer, or the standard analyzer.
|
13
|
+
# - `:eager_global_ordinals:` The Boolean indicating if global ordinals should be loaded eagerly on refresh. Defaults to false.
|
14
|
+
# - `:fielddata:` The Boolean indicating if the field can use in-memory fielddata for sorting, aggregations, or scripting. Defaults to false.
|
15
|
+
# - `:fielddata_frequency_filter:` The Hash of expert settings which allow to decide which values to load in memory when fielddata is enabled.
|
16
|
+
# - `:fields:` The Hash of multi-fields allow the same string value to be indexed in multiple ways for different purposes. By default, a 'keyword' field is added. Set to false to disable.
|
17
|
+
# - `:index:` The Boolean indicating if the field should be searchable. Defaults to true.
|
18
|
+
# - `:index_options:` The String indicating what information should be stored in the index, for search and highlighting purposes. Defaults to 'positions'.
|
19
|
+
# - `:index_prefixes:` The Hash indicating if term prefixes of between 2 and 5 characters are indexed into a separate field.
|
20
|
+
# - `:index_phrases:` The Boolean indicating if two-term word combinations (shingles) are indexed into a separate field. Defaults to false.
|
21
|
+
# - `:norms:` The Boolean indicating if field-length should be taken into account when scoring queries. Defaults to true.
|
22
|
+
# - `:position_increment_gap:` The Integer indicating the number of fake term position which should be inserted between each element of an array of strings. Defaults to 100.
|
23
|
+
# - `:store:` The Boolean indicating if the field value should be stored and retrievable separately from the _source field. Defaults to false.
|
24
|
+
# - `:search_analyzer:` The String analyzer that should be used at search time on the text field. Defaults to the analyzer setting.
|
25
|
+
# - `:search_quote_analyzer:` The String analyzer that should be used at search time when a phrase is encountered. Defaults to the search_analyzer setting.
|
26
|
+
# - `:similarity:` The String indicating which scoring algorithm or similarity should be used. Defaults to 'BM25'.
|
27
|
+
# - `:term_vector:` The String indicating if term vectors should be stored for the field. Defaults to 'no'.
|
28
|
+
# - `:meta:` The Hash of metadata about the field.
|
29
|
+
#
|
30
|
+
# ---
|
31
|
+
#
|
32
|
+
# ### Examples
|
33
|
+
#
|
34
|
+
# #### Define a string attribute
|
35
|
+
#
|
36
|
+
# ```ruby
|
37
|
+
# class MyModel < StretchyModel
|
38
|
+
# attribute :name, :string
|
39
|
+
# end
|
40
|
+
# ```
|
41
|
+
#
|
42
|
+
class String < Stretchy::Attributes::Type::Text
|
43
|
+
|
3
44
|
def type
|
4
45
|
:string
|
5
46
|
end
|
@@ -1,37 +1,57 @@
|
|
1
1
|
module Stretchy::Attributes::Type
|
2
|
-
#
|
3
|
-
#
|
4
|
-
#
|
5
|
-
#
|
6
|
-
#
|
7
|
-
#
|
8
|
-
#
|
9
|
-
#
|
10
|
-
#
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
#
|
15
|
-
#
|
16
|
-
#
|
17
|
-
#
|
18
|
-
#
|
19
|
-
#
|
20
|
-
#
|
21
|
-
#
|
22
|
-
#
|
23
|
-
#
|
24
|
-
#
|
25
|
-
#
|
26
|
-
#
|
27
|
-
#
|
2
|
+
# The Text attribute type
|
3
|
+
#
|
4
|
+
# This class is used to define a text attribute for a model. It provides support for the Elasticsearch text data type, which is a type of data type that can hold text strings.
|
5
|
+
#
|
6
|
+
# >[!NOTE]
|
7
|
+
# >
|
8
|
+
# > The default for the `:text` type is to have a keyword multified if `field:` is not specified and `fields:` is not explicitly false.
|
9
|
+
# > This can be disabled by setting `Stretchy.configuration.add_keyword_field_to_text_attributes` to false.
|
10
|
+
# > The default keyword field name is `:keyword`, but this can be changed by setting `Stretchy.configuration.default_keyword_field`.
|
11
|
+
#
|
12
|
+
# ### Parameters
|
13
|
+
#
|
14
|
+
# - `type:` `:text`.
|
15
|
+
# - `options:` The Hash of options for the attribute.
|
16
|
+
# - `:analyzer:` The String analyzer to be used for the text field, both at index-time and at search-time. Defaults to the default index analyzer, or the standard analyzer.
|
17
|
+
# - `:eager_global_ordinals:` The Boolean indicating if global ordinals should be loaded eagerly on refresh. Defaults to false.
|
18
|
+
# - `:fielddata:` The Boolean indicating if the field can use in-memory fielddata for sorting, aggregations, or scripting. Defaults to false.
|
19
|
+
# - `:fielddata_frequency_filter:` The Hash of expert settings which allow to decide which values to load in memory when fielddata is enabled.
|
20
|
+
# - `:fields:` The Hash of multi-fields allow the same string value to be indexed in multiple ways for different purposes. By default, a 'keyword' field is added. Set to false to disable.
|
21
|
+
# - `:index:` The Boolean indicating if the field should be searchable. Defaults to true.
|
22
|
+
# - `:index_options:` The String indicating what information should be stored in the index, for search and highlighting purposes. Defaults to 'positions'.
|
23
|
+
# - `:index_prefixes:` The Hash indicating if term prefixes of between 2 and 5 characters are indexed into a separate field.
|
24
|
+
# - `:index_phrases:` The Boolean indicating if two-term word combinations (shingles) are indexed into a separate field. Defaults to false.
|
25
|
+
# - `:norms:` The Boolean indicating if field-length should be taken into account when scoring queries. Defaults to true.
|
26
|
+
# - `:position_increment_gap:` The Integer indicating the number of fake term position which should be inserted between each element of an array of strings. Defaults to 100.
|
27
|
+
# - `:store:` The Boolean indicating if the field value should be stored and retrievable separately from the _source field. Defaults to false.
|
28
|
+
# - `:search_analyzer:` The String analyzer that should be used at search time on the text field. Defaults to the analyzer setting.
|
29
|
+
# - `:search_quote_analyzer:` The String analyzer that should be used at search time when a phrase is encountered. Defaults to the search_analyzer setting.
|
30
|
+
# - `:similarity:` The String indicating which scoring algorithm or similarity should be used. Defaults to 'BM25'.
|
31
|
+
# - `:term_vector:` The String indicating if term vectors should be stored for the field. Defaults to 'no'.
|
32
|
+
# - `:meta:` The Hash of metadata about the field.
|
33
|
+
#
|
34
|
+
# ---
|
35
|
+
#
|
36
|
+
# ### Examples
|
37
|
+
#
|
38
|
+
# #### Define a text attribute
|
39
|
+
#
|
40
|
+
# ```ruby
|
41
|
+
# class MyModel < StretchyModel
|
28
42
|
# attribute :description, :text, analyzer: 'english'
|
29
43
|
# end
|
44
|
+
# ```
|
30
45
|
#
|
31
|
-
# Returns nothing.
|
32
46
|
class Text < Stretchy::Attributes::Type::Base
|
33
47
|
OPTIONS = [:analyzer, :eager_global_ordinals, :fielddata, :fielddata_frequency_filter, :fields, :index, :index_options, :index_prefixes, :index_phrases, :norms, :position_increment_gap, :store, :search_analyzer, :search_quote_analyzer, :similarity, :term_vector, :meta]
|
34
|
-
|
48
|
+
|
49
|
+
def initialize(**args)
|
50
|
+
# Add a keyword field by default if no fields are specified
|
51
|
+
args.reverse_merge!(fields: {keyword: {type: :keyword, ignore_above: 256}}) if args[:fields].nil? && Stretchy.configuration.add_keyword_field_to_text_attributes
|
52
|
+
super
|
53
|
+
end
|
54
|
+
|
35
55
|
def type
|
36
56
|
:text
|
37
57
|
end
|
@@ -40,6 +60,11 @@ module Stretchy::Attributes::Type
|
|
40
60
|
:text
|
41
61
|
end
|
42
62
|
|
63
|
+
# The default for the `:text` type is to have a keyword field if no fields are specified.
|
64
|
+
def keyword_field?
|
65
|
+
fields.find { |k,d| d[:type].to_sym == :keyword}.present?
|
66
|
+
end
|
67
|
+
|
43
68
|
def mappings(name)
|
44
69
|
options = {type: type_for_database}
|
45
70
|
OPTIONS.each { |option| options[option] = send(option) unless send(option).nil? }
|
@@ -1,21 +1,31 @@
|
|
1
1
|
module Stretchy::Attributes::Type
|
2
|
-
#
|
2
|
+
# The TokenCount attribute type
|
3
3
|
#
|
4
|
-
#
|
5
|
-
# :analyzer - The String analyzer to be used to analyze the string value. Required.
|
6
|
-
# :enable_position_increments - The Boolean indicating if position increments should be counted. Defaults to true.
|
7
|
-
# :doc_values - The Boolean indicating if the field should be stored on disk in a column-stride fashion. Defaults to true.
|
8
|
-
# :index - The Boolean indicating if the field should be searchable. Defaults to true.
|
9
|
-
# :null_value - The Numeric value to be substituted for any explicit null values. Defaults to null.
|
10
|
-
# :store - The Boolean indicating if the field value should be stored and retrievable separately from the _source field. Defaults to false.
|
4
|
+
# This class is used to define a token_count attribute for a model. It provides support for the Elasticsearch token_count data type, which is a type of data type that can count the number of tokens in a string.
|
11
5
|
#
|
12
|
-
#
|
6
|
+
# ### Parameters
|
13
7
|
#
|
14
|
-
#
|
8
|
+
# - `type:` `:token_count`.
|
9
|
+
# - `options:` The Hash of options for the attribute.
|
10
|
+
# - `:analyzer:` The String analyzer to be used to analyze the string value. Required.
|
11
|
+
# - `:enable_position_increments:` The Boolean indicating if position increments should be counted. Defaults to true.
|
12
|
+
# - `:doc_values:` The Boolean indicating if the field should be stored on disk in a column-stride fashion. Defaults to true.
|
13
|
+
# - `:index:` The Boolean indicating if the field should be searchable. Defaults to true.
|
14
|
+
# - `:null_value:` The Numeric value to be substituted for any explicit null values. Defaults to null.
|
15
|
+
# - `:store:` The Boolean indicating if the field value should be stored and retrievable separately from the _source field. Defaults to false.
|
16
|
+
#
|
17
|
+
# ---
|
18
|
+
#
|
19
|
+
# ### Examples
|
20
|
+
#
|
21
|
+
# #### Define a token_count attribute
|
22
|
+
#
|
23
|
+
# ```ruby
|
24
|
+
# class MyModel < StretchyModel
|
15
25
|
# attribute :description_token_count, :token_count, analyzer: 'standard'
|
16
26
|
# end
|
27
|
+
# ```
|
17
28
|
#
|
18
|
-
# Returns nothing.
|
19
29
|
class TokenCount < Stretchy::Attributes::Type::Base
|
20
30
|
OPTIONS = [:analyzer, :enable_position_increments, :doc_values, :index, :null_value, :store]
|
21
31
|
|
@@ -1,16 +1,26 @@
|
|
1
1
|
module Stretchy::Attributes::Type
|
2
|
-
#
|
2
|
+
# The Version attribute type
|
3
3
|
#
|
4
|
-
#
|
5
|
-
# :meta - The Hash of metadata about the field.
|
4
|
+
# This class is used to define a version attribute for a model. This field type is used for software versions following the Semantic Versioning rules.
|
6
5
|
#
|
7
|
-
#
|
6
|
+
# ### Parameters
|
8
7
|
#
|
9
|
-
#
|
8
|
+
# - `type:` `:version`.
|
9
|
+
# - `options:` The Hash of options for the attribute.
|
10
|
+
# - `:meta:` The Hash of metadata about the field.
|
11
|
+
#
|
12
|
+
# ---
|
13
|
+
#
|
14
|
+
# ### Examples
|
15
|
+
#
|
16
|
+
# #### Define a version attribute
|
17
|
+
#
|
18
|
+
# ```ruby
|
19
|
+
# class MyModel < StretchyModel
|
10
20
|
# attribute :software_version, :version
|
11
21
|
# end
|
22
|
+
# ```
|
12
23
|
#
|
13
|
-
# Returns nothing.
|
14
24
|
class Version < Stretchy::Attributes::Type::Base
|
15
25
|
OPTIONS = [:meta]
|
16
26
|
|
@@ -1,33 +1,44 @@
|
|
1
1
|
module Stretchy::Attributes::Type
|
2
|
-
#
|
3
|
-
#
|
4
|
-
#
|
5
|
-
#
|
6
|
-
#
|
7
|
-
#
|
8
|
-
#
|
9
|
-
#
|
10
|
-
#
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
#
|
15
|
-
#
|
16
|
-
#
|
17
|
-
#
|
18
|
-
#
|
19
|
-
#
|
20
|
-
#
|
21
|
-
#
|
22
|
-
#
|
23
|
-
#
|
24
|
-
#
|
25
|
-
#
|
2
|
+
# The Wildcard attribute type
|
3
|
+
#
|
4
|
+
# This class is used to define a wildcard attribute for a model. This field type is a specialization of the keyword field, but it supports wildcard searches.
|
5
|
+
#
|
6
|
+
# ### Parameters
|
7
|
+
#
|
8
|
+
# - `type:` `:wildcard`.
|
9
|
+
# - `options:` The Hash of options for the attribute.
|
10
|
+
# - `:doc_values:` The Boolean indicating if the field should be stored on disk in a column-stride fashion. Defaults to true.
|
11
|
+
# - `:eager_global_ordinals:` The Boolean indicating if global ordinals should be loaded eagerly on refresh. Defaults to false.
|
12
|
+
# - `:fields:` The Hash of multi-fields for the same string value to be indexed in multiple ways.
|
13
|
+
# - `:ignore_above:` The Integer limit for the length of the string. Strings longer than this limit will not be indexed. Defaults to 2147483647.
|
14
|
+
# - `:index:` The Boolean indicating if the field should be quickly searchable. Defaults to true.
|
15
|
+
# - `:index_options:` The String indicating what information should be stored in the index for scoring purposes. Defaults to 'docs'.
|
16
|
+
# - `:meta:` The Hash metadata about the field.
|
17
|
+
# - `:norms:` The Boolean indicating if field-length should be taken into account when scoring queries. Defaults to false.
|
18
|
+
# - `:null_value:` The String value to be substituted for any explicit null values. Defaults to null.
|
19
|
+
# - `:on_script_error:` The String defining what to do if the script defined by the :script parameter throws an error at indexing time. Can be 'fail' or 'continue'.
|
20
|
+
# - `:script:` The String script that will index values generated by this script, rather than reading the values directly from the source.
|
21
|
+
# - `:store:` The Boolean indicating if the field value should be stored and retrievable separately from the _source field. Defaults to false.
|
22
|
+
# - `:similarity:` The String scoring algorithm or similarity to be used. Defaults to 'BM25'.
|
23
|
+
# - `:normalizer:` The String pre-processor for the keyword prior to indexing. Defaults to null.
|
24
|
+
# - `:split_queries_on_whitespace:` The Boolean indicating if full text queries should split the input on whitespace. Defaults to false.
|
25
|
+
# - `:time_series_dimension:` The Boolean indicating if the field is a time series dimension. Defaults to false.
|
26
|
+
#
|
27
|
+
# ---
|
28
|
+
#
|
29
|
+
# ### Examples
|
30
|
+
#
|
31
|
+
# #### Define a wildcard attribute
|
32
|
+
#
|
33
|
+
# ```ruby
|
34
|
+
# class MyModel < StretchyModel
|
26
35
|
# attribute :description_wildcard, :wildcard
|
27
36
|
# end
|
37
|
+
# ```
|
28
38
|
#
|
29
|
-
# Returns nothing.
|
30
39
|
class Wildcard < Stretchy::Attributes::Type::Keyword
|
40
|
+
OPTIONS = [:doc_values, :eager_global_ordinals, :fields, :ignore_above, :index, :index_options, :meta, :norms, :null_value, :on_script_error, :script, :store, :similarity, :normalizer, :split_queries_on_whitespace, :time_series_dimension]
|
41
|
+
attr_reader *OPTIONS
|
31
42
|
def type
|
32
43
|
:wildcard
|
33
44
|
end
|
data/lib/stretchy/attributes.rb
CHANGED
@@ -1,4 +1,32 @@
|
|
1
1
|
module Stretchy
|
2
|
+
# used to define and manage the attributes of a model in Stretchy. It provides methods for getting and setting attribute values, inspecting the model, and registering attribute types.
|
3
|
+
#
|
4
|
+
# ### Methods
|
5
|
+
#
|
6
|
+
# - `[](attribute)`: Retrieves the value of the specified attribute.
|
7
|
+
# - `[]=(attribute, value)`: Sets the value of the specified attribute.
|
8
|
+
# - `inspect`: Returns a string representation of the model, including its class name and attributes.
|
9
|
+
# - `self.inspect`: Returns a string representation of the model class, including its name and attribute types.
|
10
|
+
# - `attribute_mappings`: Returns a JSON representation of the attribute mappings for the model.
|
11
|
+
# - `self.register!`: Registers the attribute types with ActiveModel.
|
12
|
+
#
|
13
|
+
# ### Example
|
14
|
+
#
|
15
|
+
# In this example, the `Attributes` module is used to define an attribute for `MyModel`, get and set the attribute value, inspect the model and the model class, and get the attribute mappings.
|
16
|
+
#
|
17
|
+
# ```ruby
|
18
|
+
# class MyModel < Stretchy::Record
|
19
|
+
# attribute :title, :string
|
20
|
+
# end
|
21
|
+
#
|
22
|
+
# model = MyModel.new(title: "hello")
|
23
|
+
# model[:title] # => "hello"
|
24
|
+
# model.inspect # => "#<MyModel title: hello>"
|
25
|
+
# MyModel.inspect # => "#<MyModel title: string>"
|
26
|
+
# MyModel.attribute_mappings # => {properties: {title: {type: "string"}}}
|
27
|
+
# ```
|
28
|
+
#
|
29
|
+
#
|
2
30
|
module Attributes
|
3
31
|
extend ActiveSupport::Concern
|
4
32
|
|
@@ -38,11 +66,13 @@ module Stretchy
|
|
38
66
|
ActiveModel::Type.register(:ip, Stretchy::Attributes::Type::IP)
|
39
67
|
ActiveModel::Type.register(:join, Stretchy::Attributes::Type::Join)
|
40
68
|
ActiveModel::Type.register(:keyword, Stretchy::Attributes::Type::Keyword)
|
69
|
+
ActiveModel::Type.register(:knn_vector, Stretchy::Attributes::Type::KnnVector)
|
41
70
|
ActiveModel::Type.register(:match_only_text, Stretchy::Attributes::Type::MatchOnlyText)
|
42
71
|
ActiveModel::Type.register(:nested, Stretchy::Attributes::Type::Nested)
|
43
72
|
ActiveModel::Type.register(:percolator, Stretchy::Attributes::Type::Percolator)
|
44
73
|
ActiveModel::Type.register(:point, Stretchy::Attributes::Type::Point)
|
45
74
|
ActiveModel::Type.register(:rank_feature, Stretchy::Attributes::Type::RankFeature)
|
75
|
+
ActiveModel::Type.register(:rank_features, Stretchy::Attributes::Type::RankFeatures)
|
46
76
|
|
47
77
|
ActiveModel::Type.register(:text, Stretchy::Attributes::Type::Text)
|
48
78
|
ActiveModel::Type.register(:token_count, Stretchy::Attributes::Type::TokenCount)
|