stretchy-model 0.5.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. checksums.yaml +4 -4
  2. data/lib/rails/instrumentation/railtie.rb +2 -0
  3. data/lib/stretchy/associations.rb +1 -1
  4. data/lib/stretchy/attributes/type/array.rb +16 -11
  5. data/lib/stretchy/attributes/type/base.rb +42 -0
  6. data/lib/stretchy/attributes/type/binary.rb +45 -0
  7. data/lib/stretchy/attributes/type/boolean.rb +48 -0
  8. data/lib/stretchy/attributes/type/completion.rb +25 -0
  9. data/lib/stretchy/attributes/type/constant_keyword.rb +38 -0
  10. data/lib/stretchy/attributes/type/date_time.rb +35 -0
  11. data/lib/stretchy/attributes/type/dense_vector.rb +59 -0
  12. data/lib/stretchy/attributes/type/flattened.rb +31 -0
  13. data/lib/stretchy/attributes/type/geo_point.rb +27 -0
  14. data/lib/stretchy/attributes/type/geo_shape.rb +27 -0
  15. data/lib/stretchy/attributes/type/hash.rb +36 -13
  16. data/lib/stretchy/attributes/type/histogram.rb +7 -0
  17. data/lib/stretchy/attributes/type/ip.rb +29 -0
  18. data/lib/stretchy/attributes/type/join.rb +22 -0
  19. data/lib/stretchy/attributes/type/keyword.rb +36 -10
  20. data/lib/stretchy/attributes/type/match_only_text.rb +8 -0
  21. data/lib/stretchy/attributes/type/nested.rb +25 -0
  22. data/lib/stretchy/attributes/type/numeric/base.rb +32 -0
  23. data/lib/stretchy/attributes/type/numeric/byte.rb +7 -0
  24. data/lib/stretchy/attributes/type/numeric/double.rb +7 -0
  25. data/lib/stretchy/attributes/type/numeric/float.rb +7 -0
  26. data/lib/stretchy/attributes/type/numeric/half_float.rb +7 -0
  27. data/lib/stretchy/attributes/type/numeric/integer.rb +7 -0
  28. data/lib/stretchy/attributes/type/numeric/long.rb +7 -0
  29. data/lib/stretchy/attributes/type/numeric/scaled_float.rb +23 -0
  30. data/lib/stretchy/attributes/type/numeric/short.rb +7 -0
  31. data/lib/stretchy/attributes/type/numeric/unsigned_long.rb +7 -0
  32. data/lib/stretchy/attributes/type/percolator.rb +23 -0
  33. data/lib/stretchy/attributes/type/point.rb +24 -0
  34. data/lib/stretchy/attributes/type/range/base.rb +9 -0
  35. data/lib/stretchy/attributes/type/range/date_range.rb +17 -0
  36. data/lib/stretchy/attributes/type/range/double_range.rb +17 -0
  37. data/lib/stretchy/attributes/type/range/float_range.rb +16 -0
  38. data/lib/stretchy/attributes/type/range/integer_range.rb +16 -0
  39. data/lib/stretchy/attributes/type/range/ip_range.rb +16 -0
  40. data/lib/stretchy/attributes/type/range/long_range.rb +16 -0
  41. data/lib/stretchy/attributes/type/rank_feature.rb +21 -0
  42. data/lib/stretchy/attributes/type/rank_features.rb +24 -0
  43. data/lib/stretchy/attributes/type/search_as_you_type.rb +30 -0
  44. data/lib/stretchy/attributes/type/shape.rb +24 -0
  45. data/lib/stretchy/attributes/type/sparse_vector.rb +37 -0
  46. data/lib/stretchy/attributes/type/string.rb +7 -0
  47. data/lib/stretchy/attributes/type/text.rb +50 -11
  48. data/lib/stretchy/attributes/type/token_count.rb +26 -0
  49. data/lib/stretchy/attributes/type/version.rb +21 -0
  50. data/lib/stretchy/attributes/type/wildcard.rb +35 -0
  51. data/lib/stretchy/attributes.rb +46 -0
  52. data/lib/stretchy/common.rb +3 -2
  53. data/lib/stretchy/delegation/gateway_delegation.rb +2 -4
  54. data/lib/stretchy/querying.rb +3 -3
  55. data/lib/stretchy/record.rb +1 -1
  56. data/lib/stretchy/relation.rb +1 -1
  57. data/lib/stretchy/relations/finder_methods.rb +19 -2
  58. data/lib/stretchy/relations/query_builder.rb +7 -1
  59. data/lib/stretchy/scoping/named.rb +1 -1
  60. data/lib/stretchy/version.rb +1 -1
  61. data/lib/stretchy.rb +5 -1
  62. metadata +45 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dd18b424c18bda352233d72af113e9bbc944277e03a02cfb950780f0fab9a405
4
- data.tar.gz: 6eb86522e7bc91012cc4c743d0a9fccc54c7e75b14ff4d6f4fca5bdb9fa31626
3
+ metadata.gz: f23580fe0c8761ced02da75cbc44f16ab7893a559d30d9a5e0de23aa96ed790a
4
+ data.tar.gz: 821381d3e9e92822d71aac637d98f8b04a76736a80e421ca7d2c4fd05fd108d8
5
5
  SHA512:
6
- metadata.gz: 0fd2a0fb25439d79c799f43f43bb01df7c4dfe0ce9eb577d445b6d415eb9c38ecdc0f45c73d8255d2e079ff502e943f6491b874e3bb9c41fc9c853efed84d252
7
- data.tar.gz: 8ea4cfa584ec825ac30aa4aa5dea88b04c709cbf7cc75089e28cd1e850318f150f1f68ead89bc571535739aa8ff8db777102d5dd05173087d4af499bac8d8bbb
6
+ metadata.gz: 99dc36ee6cce021e869a8e1f3e2f005f546b1c50bf973434c624574c1dd601757baf4a1d39562f7ddd05bf4a1e640512111b821d8a70b8d5416bf73701b38f03
7
+ data.tar.gz: 4a58307bd7ae5a5781e7462df9c95438f66eecab5d0ae43238878d228e2ca6939a8a7643b70ac3c2586dcae537935206bfb15339415f6b3c3a70ef2518e401b4
@@ -4,6 +4,8 @@ module Stretchy
4
4
  class Railtie < ::Rails::Railtie
5
5
 
6
6
  require 'rails/instrumentation/publishers'
7
+ Stretchy.instrument!
8
+
7
9
  ActiveSupport::Notifications.subscribe 'search.stretchy' do |name, start, finish, id, payload|
8
10
  message = [
9
11
  Rainbow(" #{payload[:klass]}").bright,
@@ -38,7 +38,7 @@ module Stretchy
38
38
  end
39
39
 
40
40
  def association_reflection(association)
41
- Stretchy::Relation.new @@_associations[association], (dirty[association.to_sym] || [])
41
+ Stretchy::Relation.new @@_associations[association], (dirty[association.to_sym] || {})
42
42
  end
43
43
 
44
44
  def _destroy=(bool)
@@ -1,15 +1,20 @@
1
- module Stretchy
2
- module Attributes
3
- module Type
4
-
5
- class Array < ActiveModel::Type::Value # :nodoc:
6
-
7
- def type
8
- :array
9
- end
1
+ module Stretchy::Attributes::Type
2
+ class Array < Stretchy::Attributes::Type::Base # :nodoc:
3
+ OPTIONS = [:data_type, :fields]
4
+ def type
5
+ :array
6
+ end
10
7
 
11
- end
8
+ def type_for_database
9
+ data_type || :text
10
+ end
12
11
 
13
- end
12
+ def mappings(name)
13
+ options = {type: type_for_database}
14
+ self.class::OPTIONS.each { |option| options[option] = send(option) unless send(option).nil? }
15
+ options.delete(:fields) if fields == false
16
+ options[:fields] = {keyword: {type: :keyword, ignore_above: 256}} if type_for_database == :text && fields.nil?
17
+ { name => options }.as_json
14
18
  end
19
+ end
15
20
  end
@@ -0,0 +1,42 @@
1
+ module Stretchy
2
+ module Attributes
3
+ module Type
4
+ class Base < ActiveModel::Type::Value
5
+
6
+ OPTIONS = []
7
+
8
+
9
+ def initialize(**args)
10
+
11
+ define_option_methods!
12
+
13
+ args.each do |k, v|
14
+ if self.class::OPTIONS.include?(k)
15
+ instance_variable_set("@#{k}", v)
16
+ args.delete(k)
17
+ end
18
+ end
19
+ super
20
+ end
21
+
22
+ def mappings(name)
23
+ options = {type: type_for_database}
24
+ self.class::OPTIONS.each { |option| options[option] = send(option) unless send(option).nil? }
25
+ { name => options }.as_json
26
+ end
27
+
28
+ def type_for_database
29
+ type
30
+ end
31
+
32
+ private
33
+
34
+ def define_option_methods!
35
+ self.class::OPTIONS.each do |option|
36
+ define_singleton_method(option.to_sym) { instance_variable_get("@#{option}") }
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,45 @@
1
+ # Public: Defines a binary 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
+ # :doc_values - The Boolean indicating if the field should be stored on disk in a column-stride fashion.
6
+ # This allows it to be used later for sorting, aggregations, or scripting. Defaults to false.
7
+ # :store - The Boolean indicating if the field value should be stored and retrievable separately from the _source field. Defaults to false.
8
+ #
9
+ # Examples
10
+ #
11
+ # class MyModel
12
+ # include StretchyModel
13
+ # attribute :name, :binary, doc_values: true, store: true
14
+ # end
15
+ #
16
+ # Returns nothing.
17
+ module Stretchy
18
+ module Attributes
19
+ module Type
20
+ class Binary < ActiveModel::Type::Value
21
+ OPTIONS = [:doc_values, :store]
22
+ attr_reader *OPTIONS
23
+
24
+ def initialize(**args)
25
+ args.each do |k, v|
26
+ instance_variable_set("@#{k}", v) if OPTIONS.include?(k)
27
+ args.delete(k)
28
+ end
29
+ super
30
+ end
31
+
32
+ def type
33
+ :binary
34
+ end
35
+
36
+
37
+ def mappings(name)
38
+ options = {type: type}
39
+ OPTIONS.each { |_| options[_] = self.send(_) }
40
+ { name => options }.as_json
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,48 @@
1
+ # Public: Defines a boolean 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
+ # :doc_values - The Boolean indicating if the field should be stored on disk in a column-stride fashion.
6
+ # This allows it to be used later for sorting, aggregations, or scripting. Defaults to true.
7
+ # :index - The Boolean indicating if the field should be quickly searchable. Defaults to true.
8
+ # :ignore_malformed - The Boolean indicating if exceptions thrown when trying to index the wrong data type into a field should be ignored. Defaults to false.
9
+ # :null_value - The Boolean value to be substituted for any explicit null values. Defaults to null.
10
+ # :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'.
11
+ # :script - The String script that will index values generated by this script, rather than reading the values directly from the source.
12
+ # :store - The Boolean indicating if the field value should be stored and retrievable separately from the _source field. Defaults to false.
13
+ # :meta - The Hash metadata about the field.
14
+ #
15
+ # Examples
16
+ #
17
+ # class MyModel
18
+ # include StretchyModel
19
+ # attribute :name, :boolean, doc_values: true, store: true
20
+ # end
21
+ #
22
+ # Returns nothing.
23
+ module Stretchy
24
+ module Attributes
25
+ module Type
26
+ class Boolean < Stretchy::Attributes::Type::Base
27
+
28
+ OPTIONS = [:doc_values, :index, :ignore_malformed, :null_value, :on_script_error, :script, :store, :meta]
29
+ attr_reader *OPTIONS
30
+
31
+ def initialize(**args)
32
+ args.each do |k, v|
33
+ instance_variable_set("@#{k}", v) if OPTIONS.include?(k)
34
+ args.delete(k)
35
+ end
36
+ super
37
+ end
38
+
39
+ def type
40
+ :boolean
41
+ end
42
+
43
+
44
+
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,25 @@
1
+ module Stretchy::Attributes::Type
2
+ # Public: Defines a completion attribute for the model.
3
+ #
4
+ # opts - The Hash options used to refine the attribute (default: {}):
5
+ # :analyzer - The String index analyzer to use. Defaults to 'simple'.
6
+ # :search_analyzer - The String search analyzer to use. Defaults to the value of :analyzer.
7
+ # :preserve_separators - The Boolean indicating if separators should be preserved. Defaults to true.
8
+ # :preserve_position_increments - The Boolean indicating if position increments should be enabled. Defaults to true.
9
+ # :max_input_length - The Integer limit for the length of a single input. Defaults to 50.
10
+ #
11
+ # Examples
12
+ #
13
+ # class MyModel < Stretchy::Record
14
+ # attribute :name, :completion, analyzer: 'simple', max_input_length: 100
15
+ # end
16
+ #
17
+ # Returns nothing.
18
+ class Completion < Stretchy::Attributes::Type::Base
19
+ OPTIONS = [:analyzer, :search_analyzer, :preserve_separators, :preserve_position_increments, :max_input_length]
20
+ attr_reader *OPTIONS
21
+ def type
22
+ :completion
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,38 @@
1
+ module Stretchy::Attributes::Type
2
+ # Public: Defines a constant_keyword attribute for the model. This field type is a specialization of the keyword field, but it only accepts a single value.
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
+ # :eager_global_ordinals - The Boolean indicating if global ordinals should be loaded eagerly on refresh. Defaults to false.
7
+ # :fields - The Hash of multi-fields for the same string value to be indexed in multiple ways.
8
+ # :ignore_above - The Integer limit for the length of the string. Strings longer than this limit will not be indexed. Defaults to 2147483647.
9
+ # :index - The Boolean indicating if the field should be quickly 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
+ # :meta - The Hash metadata about the field.
12
+ # :norms - The Boolean indicating if field-length should be taken into account when scoring queries. Defaults to false.
13
+ # :null_value - The String value to be substituted for any explicit null values. Defaults to null.
14
+ # :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'.
15
+ # :script - The String script that will index values generated by this script, rather than reading the values directly from the source.
16
+ # :store - The Boolean indicating if the field value should be stored and retrievable separately from the _source field. Defaults to false.
17
+ # :similarity - The String scoring algorithm or similarity to be used. Defaults to 'BM25'.
18
+ # :normalizer - The String pre-processor for the keyword prior to indexing. Defaults to null.
19
+ # :split_queries_on_whitespace - The Boolean indicating if full text queries should split the input on whitespace. Defaults to false.
20
+ # :time_series_dimension - The Boolean indicating if the field is a time series dimension. Defaults to false.
21
+ # :value - The String value to associate with all documents in the index.
22
+ #
23
+ # Examples
24
+ #
25
+ # class MyModel
26
+ # include StretchyModel
27
+ # attribute :status, :constant_keyword, value: 'active'
28
+ # end
29
+ #
30
+ # Returns nothing.
31
+ class ConstantKeyword < Stretchy::Attributes::Type::Keyword
32
+ OPTIONS = OPTIONS + [:value]
33
+ attr_reader *OPTIONS
34
+ def type
35
+ :constant_keyword
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,35 @@
1
+ module Stretchy::Attributes::Type
2
+ # Public: Defines a datetime 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.
6
+ # This allows it to be used later for sorting, aggregations, or scripting. Defaults to true.
7
+ # :format - The String date format(s) that can be parsed. Defaults to 'strict_date_optional_time||epoch_millis'.
8
+ # :locale - The String locale to use when parsing dates. Defaults to the ROOT locale.
9
+ # :ignore_malformed - The Boolean indicating if malformed numbers should be ignored. Defaults to false.
10
+ # :index - The Boolean indicating if the field should be quickly searchable. Defaults to true.
11
+ # :null_value - The Date value to be substituted for any explicit null values. Defaults to null.
12
+ # :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'.
13
+ # :script - The String script that will index values generated by this script, rather than reading the values directly from the source.
14
+ # :store - The Boolean indicating if the field value should be stored and retrievable separately from the _source field. Defaults to false.
15
+ # :meta - The Hash metadata about the field.
16
+ #
17
+ # Examples
18
+ #
19
+ # class MyModel < Stretchy::Record
20
+ # attribute :created_at, :datetime, format: 'strict_date_optional_time||epoch_millis', locale: 'en'
21
+ # end
22
+ #
23
+ # Returns nothing.
24
+ class DateTime < Stretchy::Attributes::Type::Base
25
+ OPTIONS = [:doc_values, :format, :locale, :ignore_malformed, :index, :null_value, :on_script_error, :script, :store, :meta]
26
+ attr_reader *OPTIONS
27
+ def type
28
+ :datetime
29
+ end
30
+
31
+ def type_for_database
32
+ :date
33
+ end
34
+ end
35
+ end
@@ -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
@@ -1,17 +1,40 @@
1
- module Stretchy
2
- module Attributes
3
- module Type
4
- class Hash < ActiveModel::Type::Value # :nodoc:
5
- def type
6
- :hash
7
- end
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]
8
19
 
9
- private
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
10
35
 
11
- def cast_value(value)
12
- Elasticsearch::Model::HashWrapper[value]
13
- end
14
- end
15
- end
36
+ def cast_value(value)
37
+ Elasticsearch::Model::HashWrapper[value]
16
38
  end
39
+ end
17
40
  end
@@ -0,0 +1,7 @@
1
+ module Stretchy::Attributes::Type
2
+ class Histogram < Stretchy::Attributes::Type::Base
3
+ def type
4
+ :histogram
5
+ end
6
+ end
7
+ 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
- module Attributes
3
- module Type
4
- class Keyword < ActiveModel::Type::String # :nodoc:
5
- def type
6
- :keyword
7
- end
8
- end
9
- end
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