stretchy-model 0.4.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec +1 -1
- data/README.md +19 -84
- data/lib/rails/instrumentation/railtie.rb +2 -0
- data/lib/stretchy/associations.rb +155 -15
- data/lib/stretchy/attributes/type/array.rb +20 -0
- data/lib/stretchy/attributes/type/base.rb +42 -0
- data/lib/stretchy/attributes/type/binary.rb +45 -0
- data/lib/stretchy/attributes/type/boolean.rb +48 -0
- data/lib/stretchy/attributes/type/completion.rb +25 -0
- data/lib/stretchy/attributes/type/constant_keyword.rb +38 -0
- data/lib/stretchy/attributes/type/date_time.rb +35 -0
- data/lib/stretchy/attributes/type/dense_vector.rb +59 -0
- data/lib/stretchy/attributes/type/flattened.rb +31 -0
- data/lib/stretchy/attributes/type/geo_point.rb +27 -0
- data/lib/stretchy/attributes/type/geo_shape.rb +27 -0
- data/lib/stretchy/attributes/type/hash.rb +40 -0
- data/lib/stretchy/attributes/type/histogram.rb +7 -0
- data/lib/stretchy/attributes/type/ip.rb +29 -0
- data/lib/stretchy/attributes/type/join.rb +22 -0
- data/lib/stretchy/attributes/type/keyword.rb +36 -10
- data/lib/stretchy/attributes/type/match_only_text.rb +8 -0
- data/lib/stretchy/attributes/type/nested.rb +25 -0
- data/lib/stretchy/attributes/type/numeric/base.rb +32 -0
- data/lib/stretchy/attributes/type/numeric/byte.rb +7 -0
- data/lib/stretchy/attributes/type/numeric/double.rb +7 -0
- data/lib/stretchy/attributes/type/numeric/float.rb +7 -0
- data/lib/stretchy/attributes/type/numeric/half_float.rb +7 -0
- data/lib/stretchy/attributes/type/numeric/integer.rb +7 -0
- data/lib/stretchy/attributes/type/numeric/long.rb +7 -0
- data/lib/stretchy/attributes/type/numeric/scaled_float.rb +23 -0
- data/lib/stretchy/attributes/type/numeric/short.rb +7 -0
- data/lib/stretchy/attributes/type/numeric/unsigned_long.rb +7 -0
- data/lib/stretchy/attributes/type/percolator.rb +23 -0
- data/lib/stretchy/attributes/type/point.rb +24 -0
- data/lib/stretchy/attributes/type/range/base.rb +9 -0
- data/lib/stretchy/attributes/type/range/date_range.rb +17 -0
- data/lib/stretchy/attributes/type/range/double_range.rb +17 -0
- data/lib/stretchy/attributes/type/range/float_range.rb +16 -0
- data/lib/stretchy/attributes/type/range/integer_range.rb +16 -0
- data/lib/stretchy/attributes/type/range/ip_range.rb +16 -0
- data/lib/stretchy/attributes/type/range/long_range.rb +16 -0
- data/lib/stretchy/attributes/type/rank_feature.rb +21 -0
- data/lib/stretchy/attributes/type/rank_features.rb +24 -0
- data/lib/stretchy/attributes/type/search_as_you_type.rb +30 -0
- data/lib/stretchy/attributes/type/shape.rb +24 -0
- data/lib/stretchy/attributes/type/sparse_vector.rb +37 -0
- data/lib/stretchy/attributes/type/string.rb +7 -0
- data/lib/stretchy/attributes/type/text.rb +51 -0
- data/lib/stretchy/attributes/type/token_count.rb +26 -0
- data/lib/stretchy/attributes/type/version.rb +21 -0
- data/lib/stretchy/attributes/type/wildcard.rb +35 -0
- data/lib/stretchy/attributes.rb +68 -2
- data/lib/stretchy/common.rb +5 -5
- data/lib/stretchy/delegation/gateway_delegation.rb +9 -5
- data/lib/stretchy/model/serialization.rb +1 -0
- data/lib/stretchy/querying.rb +4 -4
- data/lib/stretchy/record.rb +9 -10
- data/lib/stretchy/relation.rb +11 -17
- data/lib/stretchy/relations/finder_methods.rb +19 -2
- data/lib/stretchy/relations/merger.rb +5 -1
- data/lib/stretchy/relations/query_builder.rb +32 -3
- data/lib/stretchy/relations/query_methods.rb +66 -2
- data/lib/stretchy/scoping/named.rb +1 -1
- data/lib/stretchy/shared_scopes.rb +1 -1
- data/lib/stretchy/version.rb +1 -1
- data/lib/stretchy.rb +5 -3
- data/lib/stretchy_model.rb +9 -0
- metadata +49 -4
- data/lib/active_model/type/array.rb +0 -13
- data/lib/active_model/type/hash.rb +0 -15
@@ -0,0 +1,59 @@
|
|
1
|
+
# Public: Defines a dense vector attribute for the model.
|
2
|
+
#
|
3
|
+
# name - The Symbol name of the attribute.
|
4
|
+
# opts - The Hash options used to refine the attribute (default: {}):
|
5
|
+
# :element_type - The String data type used to encode vectors. Can be 'float' or 'byte'.
|
6
|
+
# 'float' indexes a 4-byte floating-point value per dimension.
|
7
|
+
# 'byte' indexes a 1-byte integer value per dimension.
|
8
|
+
# Vectors using 'byte' require dimensions with integer values between -128 to 127.
|
9
|
+
# :dims - The Integer number of vector dimensions. Can’t exceed 4096.
|
10
|
+
# If not specified, it will be set to the length of the first vector added to the field.
|
11
|
+
# :index - The Boolean indicating if you can search this field using the kNN search API (default: true).
|
12
|
+
# :similarity - The String vector similarity metric to use in kNN search. Can be 'l2_norm', 'dot_product', 'cosine', or 'max_inner_product'.
|
13
|
+
# This parameter can only be specified when :index is true.
|
14
|
+
# :index_options - The Hash that configures the kNN indexing algorithm. Can only be specified when :index is true.
|
15
|
+
# :type - The String type of kNN algorithm to use. Can be either 'hnsw' or 'int8_hnsw'.
|
16
|
+
# :m - The Integer number of neighbors each node will be connected to in the HNSW graph.
|
17
|
+
# :ef_construction - The Integer number of candidates to track while assembling the list of nearest neighbors for each new node.
|
18
|
+
# :confidence_interval - The Float confidence interval to use when quantizing the vectors. Only applicable to 'int8_hnsw' index types.
|
19
|
+
#
|
20
|
+
# Examples
|
21
|
+
#
|
22
|
+
# class MyModel
|
23
|
+
# include StretchyModel
|
24
|
+
# attribute :vector_embeddings, :dense_vector, element_type: 'float', dims: 3
|
25
|
+
# end
|
26
|
+
#
|
27
|
+
# Returns nothing.
|
28
|
+
module Stretchy
|
29
|
+
module Attributes
|
30
|
+
module Type
|
31
|
+
class DenseVector < Stretchy::Attributes::Type::Base
|
32
|
+
OPTIONS = [:element_type, :dims, :index, :similarity, :index_options]
|
33
|
+
attr_reader *OPTIONS
|
34
|
+
|
35
|
+
def initialize(**args)
|
36
|
+
args.each do |k, v|
|
37
|
+
instance_variable_set("@#{k}", v) if OPTIONS.include?(k)
|
38
|
+
args.delete(k)
|
39
|
+
end
|
40
|
+
super
|
41
|
+
end
|
42
|
+
|
43
|
+
def type
|
44
|
+
:dense_vector
|
45
|
+
end
|
46
|
+
|
47
|
+
def mappings(name)
|
48
|
+
options = {type: type}
|
49
|
+
OPTIONS.each { |_| options[_] = self.send(_) }
|
50
|
+
{
|
51
|
+
properties: {
|
52
|
+
"#{name}.tokens": options
|
53
|
+
}
|
54
|
+
}.as_json
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Stretchy::Attributes::Type
|
2
|
+
# Public: Defines a flattened attribute for the model.
|
3
|
+
#
|
4
|
+
# opts - The Hash options used to refine the attribute (default: {}):
|
5
|
+
# :depth_limit - The Integer maximum allowed depth of the flattened object field. Defaults to 20.
|
6
|
+
# :doc_values - The Boolean indicating if the field should be stored on disk in a column-stride fashion. Defaults to true.
|
7
|
+
# :eager_global_ordinals - The Boolean indicating if global ordinals should be loaded eagerly on refresh. Defaults to false.
|
8
|
+
# :ignore_above - The Integer limit for the length of leaf values. Values longer than this limit will not be indexed. By default, there is no limit.
|
9
|
+
# :index - The Boolean indicating if the field should be searchable. Defaults to true.
|
10
|
+
# :index_options - The String indicating what information should be stored in the index for scoring purposes. Defaults to 'docs'.
|
11
|
+
# :null_value - The String value to be substituted for any explicit null values. Defaults to null.
|
12
|
+
# :similarity - The String scoring algorithm or similarity to be used. Defaults to 'BM25'.
|
13
|
+
# :split_queries_on_whitespace - The Boolean indicating if full text queries should split the input on whitespace. Defaults to false.
|
14
|
+
# :time_series_dimensions - The Array of Strings indicating the fields inside the flattened object that are dimensions of the time series.
|
15
|
+
#
|
16
|
+
# Examples
|
17
|
+
#
|
18
|
+
# class MyModel
|
19
|
+
# include StretchyModel
|
20
|
+
# attribute :metadata, :flattened, depth_limit: 10, index_options: 'freqs'
|
21
|
+
# end
|
22
|
+
#
|
23
|
+
# Returns nothing.
|
24
|
+
class Flattened < Stretchy::Attributes::Type::Base
|
25
|
+
OPTIONS = [:depth_limit, :doc_values, :eager_global_ordinals, :ignore_above, :index, :index_options, :null_value, :similarity, :split_queries_on_whitespace, :time_series_dimensions]
|
26
|
+
|
27
|
+
def type
|
28
|
+
:flattened
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Stretchy::Attributes::Type
|
2
|
+
# Public: Defines a geo_point attribute for the model.
|
3
|
+
#
|
4
|
+
# opts - The Hash options used to refine the attribute (default: {}):
|
5
|
+
# :ignore_malformed - The Boolean indicating if malformed geopoints should be ignored. Defaults to false.
|
6
|
+
# :ignore_z_value - The Boolean indicating if three dimension points should be accepted but only latitude and longitude values should be indexed. Defaults to true.
|
7
|
+
# :index - The Boolean indicating if the field should be quickly searchable. Defaults to true.
|
8
|
+
# :null_value - The GeoPoint value to be substituted for any explicit null values. Defaults to null.
|
9
|
+
# :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'.
|
10
|
+
# :script - The String script that will index values generated by this script, rather than reading the values directly from the source.
|
11
|
+
#
|
12
|
+
# Examples
|
13
|
+
#
|
14
|
+
# class MyModel
|
15
|
+
# include StretchyModel
|
16
|
+
# attribute :location, :geo_point, ignore_malformed: true
|
17
|
+
# end
|
18
|
+
#
|
19
|
+
# Returns nothing.
|
20
|
+
class GeoPoint < Stretchy::Attributes::Type::Base
|
21
|
+
OPTIONS = [:ignore_malformed, :ignore_z_value, :index, :null_value, :on_script_error, :script]
|
22
|
+
|
23
|
+
def type
|
24
|
+
:geo_point
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Stretchy::Attributes::Type
|
2
|
+
# Public: Defines a geo_shape attribute for the model.
|
3
|
+
#
|
4
|
+
# opts - The Hash options used to refine the attribute (default: {}):
|
5
|
+
# :orientation - The String default orientation for the field’s WKT polygons. Can be 'right', 'counterclockwise', 'ccw', 'left', 'clockwise', or 'cw'. Defaults to 'right'.
|
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 three dimension points should be accepted but only latitude and longitude values should be indexed. Defaults to true.
|
8
|
+
# :coerce - The Boolean indicating if unclosed linear rings in polygons should be automatically closed. Defaults to false.
|
9
|
+
# :index - The Boolean indicating if the field should be quickly searchable. Defaults to true.
|
10
|
+
# :doc_values - The Boolean indicating if the field should be stored on disk in a column-stride fashion. Defaults to true.
|
11
|
+
#
|
12
|
+
# Examples
|
13
|
+
#
|
14
|
+
# class MyModel
|
15
|
+
# include StretchyModel
|
16
|
+
# attribute :boundary, :geo_shape, orientation: 'left', coerce: true
|
17
|
+
# end
|
18
|
+
#
|
19
|
+
# Returns nothing.
|
20
|
+
class GeoShape < Stretchy::Attributes::Type::Base
|
21
|
+
OPTIONS = [:orientation, :ignore_malformed, :ignore_z_value, :coerce, :index, :doc_values]
|
22
|
+
|
23
|
+
def type
|
24
|
+
:geo_shape
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module Stretchy::Attributes::Type
|
2
|
+
# Public: Defines a hash attribute for the model.
|
3
|
+
#
|
4
|
+
# opts - The Hash options used to refine the attribute (default: {}):
|
5
|
+
# :dynamic - The String indicating if new properties should be added dynamically to an existing object. Can be 'true', 'runtime', 'false', or 'strict'. Defaults to 'true'.
|
6
|
+
# :enabled - The Boolean indicating if the JSON value for the object field should be parsed and indexed. Defaults to true.
|
7
|
+
# :subobjects - The Boolean indicating if the object can hold subobjects. Defaults to true.
|
8
|
+
# :properties - The Hash of fields within the object, which can be of any data type, including object.
|
9
|
+
#
|
10
|
+
# Examples
|
11
|
+
#
|
12
|
+
# class MyModel < Stretchy::Record
|
13
|
+
# attribute :metadata, :hash, dynamic: 'strict', subobjects: false
|
14
|
+
# end
|
15
|
+
#
|
16
|
+
# Returns nothing.
|
17
|
+
class Hash < Stretchy::Attributes::Type::Base
|
18
|
+
OPTIONS = [:dynamic, :enabled, :subobjects, :properties]
|
19
|
+
|
20
|
+
def type
|
21
|
+
:hash
|
22
|
+
end
|
23
|
+
|
24
|
+
def type_for_database
|
25
|
+
:object
|
26
|
+
end
|
27
|
+
|
28
|
+
def mappings(name)
|
29
|
+
options = {}
|
30
|
+
OPTIONS.each { |option| options[option] = send(option) unless send(option).nil? }
|
31
|
+
{ name => options }.as_json
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def cast_value(value)
|
37
|
+
Elasticsearch::Model::HashWrapper[value]
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Stretchy::Attributes::Type
|
2
|
+
# Public: Defines an IP attribute for the model.
|
3
|
+
#
|
4
|
+
# opts - The Hash options used to refine the attribute (default: {}):
|
5
|
+
# :doc_values - The Boolean indicating if the field should be stored on disk in a column-stride fashion. Defaults to true.
|
6
|
+
# :ignore_malformed - The Boolean indicating if malformed IP addresses should be ignored. Defaults to false.
|
7
|
+
# :index - The Boolean indicating if the field should be quickly searchable. Defaults to true.
|
8
|
+
# :null_value - The String IPv4 or IPv6 value to be substituted for any explicit null values. Defaults to null.
|
9
|
+
# :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 'reject' or 'ignore'.
|
10
|
+
# :script - The String script that will index values generated by this script, rather than reading the values directly from the source.
|
11
|
+
# :store - The Boolean indicating if the field value should be stored and retrievable separately from the _source field. Defaults to false.
|
12
|
+
# :time_series_dimension - The Boolean indicating if the field is a time series dimension. Defaults to false.
|
13
|
+
#
|
14
|
+
# Examples
|
15
|
+
#
|
16
|
+
# class MyModel
|
17
|
+
# include StretchyModel
|
18
|
+
# attribute :ip_address, :ip, ignore_malformed: true, time_series_dimension: true
|
19
|
+
# end
|
20
|
+
#
|
21
|
+
# Returns nothing.
|
22
|
+
class IP < Stretchy::Attributes::Type::Base
|
23
|
+
OPTIONS = [:doc_values, :ignore_malformed, :index, :null_value, :on_script_error, :script, :store, :time_series_dimension]
|
24
|
+
|
25
|
+
def type
|
26
|
+
:ip
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Stretchy::Attributes::Type
|
2
|
+
# Public: Defines a join attribute for the model.
|
3
|
+
#
|
4
|
+
# opts - The Hash options used to define the parent/child relation within documents of the same index (default: {}):
|
5
|
+
# :relations - The Hash defining a set of possible relations within the documents, each relation being a parent name and a child name.
|
6
|
+
#
|
7
|
+
# Examples
|
8
|
+
#
|
9
|
+
# class MyModel
|
10
|
+
# include StretchyModel
|
11
|
+
# attribute :relation, :join, relations: { question: :answer }
|
12
|
+
# end
|
13
|
+
#
|
14
|
+
# Returns nothing.
|
15
|
+
class Join < Stretchy::Attributes::Type::Base
|
16
|
+
OPTIONS = [:relations]
|
17
|
+
|
18
|
+
def type
|
19
|
+
:join
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -1,11 +1,37 @@
|
|
1
|
-
module Stretchy
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
1
|
+
module Stretchy::Attributes::Type
|
2
|
+
# Public: Defines a keyword attribute for the model.
|
3
|
+
#
|
4
|
+
# opts - The Hash options used to refine the attribute (default: {}):
|
5
|
+
#
|
6
|
+
# :doc_values - The Boolean indicating if the field should be stored on disk in a column-stride fashion. Defaults to true.
|
7
|
+
# :eager_global_ordinals - The Boolean indicating if global ordinals should be loaded eagerly on refresh. Defaults to false.
|
8
|
+
# :fields - The Hash of multi-fields for the same string value to be indexed in multiple ways.
|
9
|
+
# :ignore_above - The Integer limit for the length of the string. Strings longer than this limit will not be indexed. Defaults to 2147483647.
|
10
|
+
# :index - The Boolean indicating if the field should be quickly searchable. Defaults to true.
|
11
|
+
# :index_options - The String indicating what information should be stored in the index for scoring purposes. Defaults to 'docs'.
|
12
|
+
# :meta - The Hash metadata about the field.
|
13
|
+
# :norms - The Boolean indicating if field-length should be taken into account when scoring queries. Defaults to false.
|
14
|
+
# :null_value - The String value to be substituted for any explicit null values. Defaults to null.
|
15
|
+
# :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'.
|
16
|
+
# :script - The String script that will index values generated by this script, rather than reading the values directly from the source.
|
17
|
+
# :store - The Boolean indicating if the field value should be stored and retrievable separately from the _source field. Defaults to false.
|
18
|
+
# :similarity - The String scoring algorithm or similarity to be used. Defaults to 'BM25'.
|
19
|
+
# :normalizer - The String pre-processor for the keyword prior to indexing. Defaults to null.
|
20
|
+
# :split_queries_on_whitespace - The Boolean indicating if full text queries should split the input on whitespace. Defaults to false.
|
21
|
+
# :time_series_dimension - The Boolean indicating if the field is a time series dimension. Defaults to false.
|
22
|
+
#
|
23
|
+
# Examples
|
24
|
+
# class MyModel
|
25
|
+
# include StretchyModel
|
26
|
+
# attribute :tag, :keyword, ignore_above: 256, time_series_dimension: true
|
27
|
+
# end
|
28
|
+
#
|
29
|
+
# Returns nothing.
|
30
|
+
class Keyword < Stretchy::Attributes::Type::Base
|
31
|
+
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]
|
32
|
+
|
33
|
+
def type
|
34
|
+
:keyword
|
35
|
+
end
|
10
36
|
end
|
11
|
-
end
|
37
|
+
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
# a space-optimized variant of text that disables scoring and performs slower on queries that need positions. It is best suited for indexing log messages.
|
2
|
+
module Stretchy::Attributes::Type
|
3
|
+
class MatchOnlyText < Stretchy::Attributes::Type::Text
|
4
|
+
def type
|
5
|
+
:match_only_text
|
6
|
+
end
|
7
|
+
end
|
8
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Stretchy::Attributes::Type
|
2
|
+
# Public: Defines a nested attribute for the model.
|
3
|
+
#
|
4
|
+
# opts - The Hash options used to refine the attribute (default: {}):
|
5
|
+
# :dynamic - The String indicating if new properties should be added dynamically to an existing nested object. Can be 'true', 'false', or 'strict'. Defaults to 'true'.
|
6
|
+
# :properties - The Hash of fields within the nested object, which can be of any data type, including nested.
|
7
|
+
# :include_in_parent - The Boolean indicating if all fields in the nested object are also added to the parent document as standard fields. Defaults to false.
|
8
|
+
# :include_in_root - The Boolean indicating if all fields in the nested object are also added to the root document as standard fields. Defaults to false.
|
9
|
+
#
|
10
|
+
# Examples
|
11
|
+
#
|
12
|
+
# class MyModel
|
13
|
+
# include StretchyModel
|
14
|
+
# attribute :metadata, :nested, dynamic: 'strict', include_in_parent: true
|
15
|
+
# end
|
16
|
+
#
|
17
|
+
# Returns nothing.
|
18
|
+
class Nested < Stretchy::Attributes::Type::Base
|
19
|
+
OPTIONS = [:dynamic, :properties, :include_in_parent, :include_in_root]
|
20
|
+
|
21
|
+
def type
|
22
|
+
:nested
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Stretchy::Attributes::Type::Numeric
|
2
|
+
# Public: Defines a numeric attribute for the model. This is a base class for numeric types.
|
3
|
+
#
|
4
|
+
# opts - The Hash options used to refine the attribute (default: {}):
|
5
|
+
# :coerce - The Boolean indicating if strings should be converted to numbers and fractions truncated for integers. Defaults to true.
|
6
|
+
# :doc_values - The Boolean indicating if the field should be stored on disk in a column-stride fashion. Defaults to true.
|
7
|
+
# :ignore_malformed - The Boolean indicating if malformed numbers should be ignored. Defaults to false.
|
8
|
+
# :index - The Boolean indicating if the field should be quickly searchable. Defaults to true.
|
9
|
+
# :meta - The Hash metadata about the field.
|
10
|
+
# :null_value - The Numeric value to be substituted for any explicit null values. Defaults to null.
|
11
|
+
# :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'.
|
12
|
+
# :script - The String script that will index values generated by this script, rather than reading the values directly from the source.
|
13
|
+
# :store - The Boolean indicating if the field value should be stored and retrievable separately from the _source field. Defaults to false.
|
14
|
+
# :time_series_dimension - The Boolean indicating if the field is a time series dimension. Defaults to false.
|
15
|
+
# :time_series_metric - The String indicating if the field is a time series metric. Can be 'counter', 'gauge', or 'null'.
|
16
|
+
#
|
17
|
+
# Examples
|
18
|
+
#
|
19
|
+
# class MyModel
|
20
|
+
# include StretchyModel
|
21
|
+
# attribute :age, :integer, coerce: false, time_series_dimension: true
|
22
|
+
# end
|
23
|
+
#
|
24
|
+
# Returns nothing.
|
25
|
+
class Base < Stretchy::Attributes::Type::Base
|
26
|
+
OPTIONS = [:coerce, :doc_values, :ignore_malformed, :index, :meta, :null_value, :on_script_error, :script, :store, :time_series_dimension, :time_series_metric]
|
27
|
+
|
28
|
+
def type
|
29
|
+
raise NotImplementedError, "You must use one of the numeric types: integer, long, short, byte, double, float, half_float, scaled_float."
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Stretchy::Attributes::Type::Numeric
|
2
|
+
|
3
|
+
# Public: Defines a scaled_float attribute for the model.
|
4
|
+
#
|
5
|
+
# opts - The Hash options used to refine the attribute (default: {}):
|
6
|
+
# :scaling_factor - The Integer scaling factor to use when encoding values. This parameter is required.
|
7
|
+
#
|
8
|
+
# Examples
|
9
|
+
#
|
10
|
+
# class MyModel
|
11
|
+
# include StretchyModel
|
12
|
+
# attribute :rating, :scaled_float, scaling_factor: 10
|
13
|
+
# end
|
14
|
+
#
|
15
|
+
# Returns nothing.
|
16
|
+
class ScaledFloat < Base
|
17
|
+
OPTIONS = Base::OPTIONS + [:scaling_factor]
|
18
|
+
|
19
|
+
def type
|
20
|
+
:scaled_float
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Stretchy::Attributes::Type
|
2
|
+
# Public: Defines a percolator attribute for the model.
|
3
|
+
#
|
4
|
+
# The percolator field type parses a JSON structure into a native query and stores that query,
|
5
|
+
# so that the percolate query can use it to match provided documents.
|
6
|
+
#
|
7
|
+
# Any field that contains a JSON object can be configured to be a percolator field.
|
8
|
+
# The percolator field type has no settings. Just configuring the percolator field type
|
9
|
+
# is sufficient to instruct Elasticsearch to treat a field as a query.
|
10
|
+
#
|
11
|
+
# Examples
|
12
|
+
#
|
13
|
+
# class MyModel < Stretchy::Record
|
14
|
+
# attribute :query, :percolator
|
15
|
+
# end
|
16
|
+
#
|
17
|
+
# Returns nothing.
|
18
|
+
class Percolator < Stretchy::Attributes::Type::Base
|
19
|
+
def type
|
20
|
+
:percolator
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Stretchy::Attributes::Type
|
2
|
+
# Public: Defines a point attribute for the model.
|
3
|
+
#
|
4
|
+
# opts - The Hash options used to refine the attribute (default: {}):
|
5
|
+
# :ignore_malformed - The Boolean indicating if malformed points should be ignored. Defaults to false.
|
6
|
+
# :ignore_z_value - The Boolean indicating if the z value of three dimension points should be ignored. Defaults to true.
|
7
|
+
# :null_value - The Point value to be substituted for any explicit null values. Defaults to null.
|
8
|
+
#
|
9
|
+
# Examples
|
10
|
+
#
|
11
|
+
# class MyModel
|
12
|
+
# include StretchyModel
|
13
|
+
# attribute :location, :point, ignore_malformed: true
|
14
|
+
# end
|
15
|
+
#
|
16
|
+
# Returns nothing.
|
17
|
+
class Point < Stretchy::Attributes::Type::Base
|
18
|
+
OPTIONS = [:ignore_malformed, :ignore_z_value, :null_value]
|
19
|
+
|
20
|
+
def type
|
21
|
+
:point
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
module Stretchy::Attributes::Type::Range
|
2
|
+
class Base < Stretchy::Attributes::Type::Base
|
3
|
+
OPTIONS = [:coerce, :index, :store]
|
4
|
+
|
5
|
+
def type
|
6
|
+
raise NotImplementedError, "You must use one of the range types: integer_range, float_range, long_range, double_range, date_range, or ip_range."
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Stretchy::Attributes::Type::Range
|
2
|
+
# Public: Defines a date_range attribute for the model.
|
3
|
+
#
|
4
|
+
# Examples
|
5
|
+
#
|
6
|
+
# class MyModel < Stretchy::Record
|
7
|
+
# attribute :birth_date_range, :date_range
|
8
|
+
# end
|
9
|
+
#
|
10
|
+
# Returns nothing.
|
11
|
+
class DateRange < Base
|
12
|
+
|
13
|
+
def type
|
14
|
+
:date_range
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Stretchy::Attributes::Type::Range
|
2
|
+
# Public: Defines a double_range attribute for the model.
|
3
|
+
#
|
4
|
+
# Examples
|
5
|
+
#
|
6
|
+
# class MyModel < Stretchy::Record
|
7
|
+
# attribute :weight_range, :double_range
|
8
|
+
# end
|
9
|
+
#
|
10
|
+
# Returns nothing.
|
11
|
+
class DoubleRange < Base
|
12
|
+
|
13
|
+
def type
|
14
|
+
:double_range
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Stretchy::Attributes::Type::Range
|
2
|
+
# Public: Defines a float_range attribute for the model.
|
3
|
+
#
|
4
|
+
# Examples
|
5
|
+
#
|
6
|
+
# class MyModel < Stretchy::Record
|
7
|
+
# attribute :rating_range, :float_range
|
8
|
+
# end
|
9
|
+
#
|
10
|
+
# Returns nothing.
|
11
|
+
class FloatRange < Base
|
12
|
+
def type
|
13
|
+
:float_range
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Stretchy::Attributes::Type::Range
|
2
|
+
# Public: Defines an integer_range attribute for the model.
|
3
|
+
#
|
4
|
+
# Examples
|
5
|
+
#
|
6
|
+
# class MyModel < Stretchy::Record
|
7
|
+
# attribute :age_range, :integer_range
|
8
|
+
# end
|
9
|
+
#
|
10
|
+
# Returns nothing.
|
11
|
+
class IntegerRange < Base
|
12
|
+
def type
|
13
|
+
:integer_range
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Stretchy::Attributes::Type::Range
|
2
|
+
# Public: Defines an ip_range attribute for the model.
|
3
|
+
#
|
4
|
+
# Examples
|
5
|
+
#
|
6
|
+
# class MyModel < Stretchy::Record
|
7
|
+
# attribute :ip_range, :ip_range
|
8
|
+
# end
|
9
|
+
#
|
10
|
+
# Returns nothing.
|
11
|
+
class IpRange < Base
|
12
|
+
def type
|
13
|
+
:ip_range
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Stretchy::Attributes::Type::Range
|
2
|
+
# Public: Defines a long_range attribute for the model.
|
3
|
+
#
|
4
|
+
# Examples
|
5
|
+
#
|
6
|
+
# class MyModel < Stretchy::Record
|
7
|
+
# attribute :population_range, :long_range
|
8
|
+
# end
|
9
|
+
#
|
10
|
+
# Returns nothing.
|
11
|
+
class LongRange < Base
|
12
|
+
def type
|
13
|
+
:long_range
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Stretchy::Attributes::Type
|
2
|
+
# Public: Defines a rank_feature attribute for the model.
|
3
|
+
#
|
4
|
+
# opts - The Hash options used to refine the attribute (default: {}):
|
5
|
+
# :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.
|
6
|
+
#
|
7
|
+
# Examples
|
8
|
+
#
|
9
|
+
# class MyModel < Stretchy::Record
|
10
|
+
# attribute :url_length, :rank_feature, positive_score_impact: false
|
11
|
+
# end
|
12
|
+
#
|
13
|
+
# Returns nothing.
|
14
|
+
class RankFeature < Stretchy::Attributes::Type::Base
|
15
|
+
OPTIONS = [:positive_score_impact]
|
16
|
+
|
17
|
+
def type
|
18
|
+
:rank_feature
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|