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
@@ -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,7 @@
1
+ module Stretchy::Attributes::Type::Numeric
2
+ class Byte < Base
3
+ def type
4
+ :byte
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module Stretchy::Attributes::Type::Numeric
2
+ class Double < Base
3
+ def type
4
+ :double
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module Stretchy::Attributes::Type::Numeric
2
+ class Float < Base
3
+ def type
4
+ :float
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module Stretchy::Attributes::Type::Numeric
2
+ class HalfFloat < Base
3
+ def type
4
+ :half_float
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module Stretchy::Attributes::Type::Numeric
2
+ class Integer < Stretchy::Attributes::Type::Base # :nodoc:
3
+ def type
4
+ :integer
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module Stretchy::Attributes::Type::Numeric
2
+ class Long < Base
3
+ def type
4
+ :long
5
+ end
6
+ end
7
+ 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,7 @@
1
+ module Stretchy::Attributes::Type::Numeric
2
+ class Short < Base
3
+ def type
4
+ :short
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module Stretchy::Attributes::Type::Numeric
2
+ class UnsignedLong < Stretchy::Attributes::Type::Numeric::Base
3
+ def type
4
+ :unsigned_long
5
+ end
6
+ end
7
+ 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
@@ -0,0 +1,24 @@
1
+ module Stretchy::Attributes::Type
2
+ # Public: Defines a rank_features attribute for the model.
3
+ #
4
+ # A rank_features field can index numeric feature vectors, so that they can later be used to boost documents in queries with a rank_feature query.
5
+
6
+ # It is analogous to the rank_feature data type but 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.
7
+ # opts - The Hash options used to refine the attribute (default: {}):
8
+ # :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.
9
+ #
10
+ # Examples
11
+ #
12
+ # class MyModel < Stretchy::Record
13
+ # attribute :negative_reviews, :rank_features, positive_score_impact: false
14
+ # end
15
+ #
16
+ # Returns nothing.
17
+ class RankFeatures < Stretchy::Attributes::Type::Base
18
+ OPTIONS = [:positive_score_impact]
19
+
20
+ def type
21
+ :rank_features
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,30 @@
1
+ module Stretchy::Attributes::Type
2
+ # Public: Defines a search_as_you_type attribute for the model. This field type is optimized to provide out-of-the-box support for queries that serve an as-you-type completion use case.
3
+ #
4
+ # opts - The Hash options used to refine the attribute (default: {}):
5
+ # :max_shingle_size - The Integer indicating the largest shingle size to create. Valid values are 2 to 4. Defaults to 3.
6
+ # :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.
7
+ # :index - The Boolean indicating if the field should be searchable. Defaults to true.
8
+ # :index_options - The String indicating what information should be stored in the index, for search and highlighting purposes. Defaults to 'positions'.
9
+ # :norms - The Boolean indicating if field-length should be taken into account when scoring queries. Defaults to true.
10
+ # :store - The Boolean indicating if the field value should be stored and retrievable separately from the _source field. Defaults to false.
11
+ # :search_analyzer - The String analyzer that should be used at search time on text fields. Defaults to the analyzer setting.
12
+ # :search_quote_analyzer - The String analyzer that should be used at search time when a phrase is encountered. Defaults to the search_analyzer setting.
13
+ # :similarity - The String indicating which scoring algorithm or similarity should be used. Defaults to 'BM25'.
14
+ # :term_vector - The String indicating if term vectors should be stored for the field. Defaults to 'no'.
15
+ #
16
+ # Examples
17
+ #
18
+ # class MyModel < Stretchy::Record
19
+ # attribute :name, :search_as_you_type, max_shingle_size: 4
20
+ # end
21
+ #
22
+ # Returns nothing.
23
+ class SearchAsYouType < Stretchy::Attributes::Type::Base
24
+ OPTIONS = [:max_shingle_size, :analyzer, :index, :index_options, :norms, :store, :search_analyzer, :search_quote_analyzer, :similarity, :term_vector]
25
+
26
+ def type
27
+ :search_as_you_type
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,24 @@
1
+ module Stretchy::Attributes::Type
2
+ # Public: Defines a shape attribute for the model. This field type is used for complex shapes.
3
+ #
4
+ # opts - The Hash options used to refine the attribute (default: {}):
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.
9
+ #
10
+ # Examples
11
+ #
12
+ # class MyModel < Stretchy::Record
13
+ # attribute :boundary, :shape, orientation: 'cw'
14
+ # end
15
+ #
16
+ # Returns nothing.
17
+ class Shape < Stretchy::Attributes::Type::Base
18
+ OPTIONS = [:orientation, :ignore_malformed, :ignore_z_value, :coerce]
19
+
20
+ def type
21
+ :shape
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,37 @@
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
+ module Stretchy
17
+ module Attributes
18
+ module Type
19
+ class SparseVector < Stretchy::Attributes::Type::Base
20
+
21
+ def type
22
+ :sparse_vector
23
+ end
24
+
25
+ def mappings(name)
26
+ {
27
+ properties: {
28
+ "#{name}.tokens": {
29
+ type: "sparse_vector"
30
+ }
31
+ }
32
+ }.as_json
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,7 @@
1
+ module Stretchy::Attributes::Type
2
+ class String < Stretchy::Attributes::Type::Text # :nodoc:
3
+ def type
4
+ :string
5
+ end
6
+ end
7
+ end
@@ -1,12 +1,51 @@
1
- module Stretchy
2
- module Attributes
3
- module Type
4
- # alias for ActiveModel::Type::String
5
- class Text < ActiveModel::Type::String
6
- def type
7
- :text
8
- end
9
- end
1
+ module Stretchy::Attributes::Type
2
+ # Public: Defines a text attribute for the model. This field type is used for text strings.
3
+ #
4
+ # opts - The Hash options used to refine the attribute (default: {}):
5
+ # :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.
6
+ # :eager_global_ordinals - The Boolean indicating if global ordinals should be loaded eagerly on refresh. Defaults to false.
7
+ # :fielddata - The Boolean indicating if the field can use in-memory fielddata for sorting, aggregations, or scripting. Defaults to false.
8
+ # :fielddata_frequency_filter - The Hash of expert settings which allow to decide which values to load in memory when fielddata is enabled.
9
+ # :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.
10
+ # :index - The Boolean indicating if the field should be searchable. Defaults to true.
11
+ # :index_options - The String indicating what information should be stored in the index, for search and highlighting purposes. Defaults to 'positions'.
12
+ # :index_prefixes - The Hash indicating if term prefixes of between 2 and 5 characters are indexed into a separate field.
13
+ # :index_phrases - The Boolean indicating if two-term word combinations (shingles) are indexed into a separate field. Defaults to false.
14
+ # :norms - The Boolean indicating if field-length should be taken into account when scoring queries. Defaults to true.
15
+ # :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.
16
+ # :store - The Boolean indicating if the field value should be stored and retrievable separately from the _source field. Defaults to false.
17
+ # :search_analyzer - The String analyzer that should be used at search time on the text field. Defaults to the analyzer setting.
18
+ # :search_quote_analyzer - The String analyzer that should be used at search time when a phrase is encountered. Defaults to the search_analyzer setting.
19
+ # :similarity - The String indicating which scoring algorithm or similarity should be used. Defaults to 'BM25'.
20
+ # :term_vector - The String indicating if term vectors should be stored for the field. Defaults to 'no'.
21
+ # :meta - The Hash of metadata about the field.
22
+ #
23
+ #
24
+ # Examples
25
+ #
26
+ # class MyModel
27
+ # include StretchyModel
28
+ # attribute :description, :text, analyzer: 'english'
29
+ # end
30
+ #
31
+ # Returns nothing.
32
+ class Text < Stretchy::Attributes::Type::Base
33
+ 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
+
35
+ def type
36
+ :text
10
37
  end
11
- end
12
- end
38
+
39
+ def type_for_database
40
+ :text
41
+ end
42
+
43
+ def mappings(name)
44
+ options = {type: type_for_database}
45
+ OPTIONS.each { |option| options[option] = send(option) unless send(option).nil? }
46
+ options.delete(:fields) if fields == false
47
+ options[:fields] = {keyword: {type: :keyword, ignore_above: 256}} if fields.nil?
48
+ { name => options }.as_json
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,26 @@
1
+ module Stretchy::Attributes::Type
2
+ # Public: Defines a token_count attribute for the model. This field type is used for counting the number of tokens in a string.
3
+ #
4
+ # opts - The Hash options used to refine the attribute (default: {}):
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.
11
+ #
12
+ # Examples
13
+ #
14
+ # class MyModel < Stretchy::Record
15
+ # attribute :description_token_count, :token_count, analyzer: 'standard'
16
+ # end
17
+ #
18
+ # Returns nothing.
19
+ class TokenCount < Stretchy::Attributes::Type::Base
20
+ OPTIONS = [:analyzer, :enable_position_increments, :doc_values, :index, :null_value, :store]
21
+
22
+ def type
23
+ :token_count
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,21 @@
1
+ module Stretchy::Attributes::Type
2
+ # Public: Defines a version attribute for the model. This field type is used for software versions following the Semantic Versioning rules.
3
+ #
4
+ # opts - The Hash options used to refine the attribute (default: {}):
5
+ # :meta - The Hash of metadata about the field.
6
+ #
7
+ # Examples
8
+ #
9
+ # class MyModel < Stretchy::Record
10
+ # attribute :software_version, :version
11
+ # end
12
+ #
13
+ # Returns nothing.
14
+ class Version < Stretchy::Attributes::Type::Base
15
+ OPTIONS = [:meta]
16
+
17
+ def type
18
+ :version
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,35 @@
1
+ module Stretchy::Attributes::Type
2
+ # Public: Defines a wildcard attribute for the model. This field type is a specialization of the keyword field, but it supports wildcard searches.
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
+ #
22
+ # Examples
23
+ #
24
+ # class MyModel
25
+ # include StretchyModel
26
+ # attribute :description_wildcard, :wildcard
27
+ # end
28
+ #
29
+ # Returns nothing.
30
+ class Wildcard < Stretchy::Attributes::Type::Keyword
31
+ def type
32
+ :wildcard
33
+ end
34
+ end
35
+ end
@@ -18,13 +18,59 @@ module Stretchy
18
18
  def inspect
19
19
  "#<#{self.name} #{attribute_types.map { |k,v| "#{k}: #{v.type}" }.join(', ')}>"
20
20
  end
21
+
22
+ def attribute_mappings
23
+ {properties: attribute_types.map { |k,v| v.mappings(k) }.reduce({}, :merge)}.as_json
24
+ end
21
25
  end
22
26
 
23
27
  def self.register!
24
28
  ActiveModel::Type.register(:array, Stretchy::Attributes::Type::Array)
29
+ ActiveModel::Type.register(:binary, Stretchy::Attributes::Type::Binary)
30
+ ActiveModel::Type.register(:boolean, Stretchy::Attributes::Type::Boolean)
31
+ ActiveModel::Type.register(:constant_keyword, Stretchy::Attributes::Type::ConstantKeyword)
32
+ ActiveModel::Type.register(:datetime, Stretchy::Attributes::Type::DateTime)
33
+ ActiveModel::Type.register(:flattened, Stretchy::Attributes::Type::Flattened)
34
+ ActiveModel::Type.register(:geo_point, Stretchy::Attributes::Type::GeoPoint)
35
+ ActiveModel::Type.register(:geo_shape, Stretchy::Attributes::Type::GeoShape)
36
+ ActiveModel::Type.register(:histogram, Stretchy::Attributes::Type::Histogram)
25
37
  ActiveModel::Type.register(:hash, Stretchy::Attributes::Type::Hash)
38
+ ActiveModel::Type.register(:ip, Stretchy::Attributes::Type::IP)
39
+ ActiveModel::Type.register(:join, Stretchy::Attributes::Type::Join)
26
40
  ActiveModel::Type.register(:keyword, Stretchy::Attributes::Type::Keyword)
41
+ ActiveModel::Type.register(:match_only_text, Stretchy::Attributes::Type::MatchOnlyText)
42
+ ActiveModel::Type.register(:nested, Stretchy::Attributes::Type::Nested)
43
+ ActiveModel::Type.register(:percolator, Stretchy::Attributes::Type::Percolator)
44
+ ActiveModel::Type.register(:point, Stretchy::Attributes::Type::Point)
45
+ ActiveModel::Type.register(:rank_feature, Stretchy::Attributes::Type::RankFeature)
46
+
27
47
  ActiveModel::Type.register(:text, Stretchy::Attributes::Type::Text)
48
+ ActiveModel::Type.register(:token_count, Stretchy::Attributes::Type::TokenCount)
49
+ ActiveModel::Type.register(:dense_vector, Stretchy::Attributes::Type::DenseVector)
50
+
51
+ ActiveModel::Type.register(:search_as_you_type, Stretchy::Attributes::Type::SearchAsYouType)
52
+ ActiveModel::Type.register(:sparse_vector, Stretchy::Attributes::Type::SparseVector)
53
+ ActiveModel::Type.register(:string, Stretchy::Attributes::Type::String)
54
+ ActiveModel::Type.register(:version, Stretchy::Attributes::Type::Version)
55
+ ActiveModel::Type.register(:wildcard, Stretchy::Attributes::Type::Wildcard)
56
+ # Numerics
57
+ ActiveModel::Type.register(:long, Stretchy::Attributes::Type::Numeric::Long)
58
+ ActiveModel::Type.register(:integer, Stretchy::Attributes::Type::Numeric::Integer)
59
+ ActiveModel::Type.register(:short, Stretchy::Attributes::Type::Numeric::Short)
60
+ ActiveModel::Type.register(:byte, Stretchy::Attributes::Type::Numeric::Byte)
61
+ ActiveModel::Type.register(:double, Stretchy::Attributes::Type::Numeric::Double)
62
+ ActiveModel::Type.register(:float, Stretchy::Attributes::Type::Numeric::Float)
63
+ ActiveModel::Type.register(:half_float, Stretchy::Attributes::Type::Numeric::HalfFloat)
64
+ ActiveModel::Type.register(:scaled_float, Stretchy::Attributes::Type::Numeric::ScaledFloat)
65
+ ActiveModel::Type.register(:unsigned_long, Stretchy::Attributes::Type::Numeric::UnsignedLong)
66
+ # Ranges
67
+ ActiveModel::Type.register(:integer_range, Stretchy::Attributes::Type::Range::IntegerRange)
68
+ ActiveModel::Type.register(:float_range, Stretchy::Attributes::Type::Range::FloatRange)
69
+ ActiveModel::Type.register(:long_range, Stretchy::Attributes::Type::Range::LongRange)
70
+ ActiveModel::Type.register(:double_range, Stretchy::Attributes::Type::Range::DoubleRange)
71
+ ActiveModel::Type.register(:date_range, Stretchy::Attributes::Type::Range::DateRange)
72
+ ActiveModel::Type.register(:ip_range, Stretchy::Attributes::Type::Range::IpRange)
73
+
28
74
  end
29
75
  end
30
76
  end