jay_api 29.9.0 → 29.11.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e0a1faee742a3503bae215225c1a111f9cb21b21e94ffb83b10fcd16d14f71e1
4
- data.tar.gz: b39ed836b7bef2233a3833d9b9e56f5234f4b542fd10f1a4fb7fc35b85e85e37
3
+ metadata.gz: af422ade60e62cb63cd97d8fd51892cd9876143e8fee61da5ac64666ad70e4ed
4
+ data.tar.gz: bb7c1cbf24070575ea3db15d5056e7b22389b62e1199c7243c5243aa07722cf6
5
5
  SHA512:
6
- metadata.gz: 4963d63c87ed8d756e94984ec635d53cb4db539e6fba42632be2ecd8f5cf79443485ededadaddf9f15988414db7e37b07b515f2d37529fcc074de8d57bf6f2f4
7
- data.tar.gz: 9db8b8d9600477ded9c07058d26af30de56153717adc5cdd9dc179bd0b2893225936fbdecb2281a0d5e06859ad6797eee3554d89e3531d88d449042040f266d2
6
+ metadata.gz: ce6602395fb91182c762e7bcf6d32a2391731087af461b6b67a6f2ed2d563b65bd46f011eae1bd04f0ee45e337749567098257616c41265d46b70a39d6b3d33c
7
+ data.tar.gz: 8344f2770b7c707a045d01159ff71c91fefe3058a742177e1a670a707a956fc9bd190b512f1ae56f23c70f39287eeac633e73367ef57fd02745f07d0e8135fd3
data/CHANGELOG.md CHANGED
@@ -8,6 +8,22 @@ Please mark backwards incompatible changes with an exclamation mark at the start
8
8
 
9
9
  ## [Unreleased]
10
10
 
11
+ ## [29.11.0] - 2026-09-03
12
+
13
+ ### Added
14
+ - The `_source` parameter for Elasticsearch's `TopHits` aggregation.
15
+ - The `sort` parameter for Elasticsearch's `TopHits` aggregation.
16
+ - The `missing` parameter for Elasticsearch's `Terms` aggregation.
17
+
18
+ ## [29.10.0] - 2026-08-21
19
+
20
+ ### Added
21
+ - The `JayAPI::Elasticsearch::QueryBuilder::QueryClauses::Prefix` class and the
22
+ corresponding `#prefix` method to the `MatchClauses` module. This allows the
23
+ use of Elasticsearch's
24
+ [prefix](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-prefix-query.html)
25
+ query with the Query Builder.
26
+
11
27
  ## [29.9.0] - 2026-08-04
12
28
 
13
29
  ### Added
@@ -14,7 +14,7 @@ module JayAPI
14
14
  # Information about this type of aggregation can be found in:
15
15
  # https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-terms-aggregation.html
16
16
  class Terms < ::JayAPI::Elasticsearch::QueryBuilder::Aggregations::Aggregation
17
- attr_reader :field, :script, :size, :order
17
+ attr_reader :field, :script, :size, :order, :missing
18
18
 
19
19
  # @param [String] name The name used by Elasticsearch to identify each
20
20
  # of the aggregations.
@@ -29,9 +29,15 @@ module JayAPI
29
29
  # aggregation. By default, the +terms+ aggregation orders terms by
30
30
  # descending document +_count+. This can be changed by providing a
31
31
  # custom +order+ hash.
32
+ # @param [String] missing The value to use for documents that are
33
+ # missing a value in the given +field+ or for whom the +script+
34
+ # returns +null+. When +missing+ is not given, such documents are
35
+ # ignored.
32
36
  # @raise [ArgumentError] If neither a +field+ nor a +script+ are given
33
37
  # or if both of them are given. Only one should be present.
34
- def initialize(name, field: nil, script: nil, size: nil, order: nil)
38
+ # rubocop:disable Metrics/ParameterLists -- Constraint by Elasticsearch's design
39
+ # :reek:LongParameterList -- Constraint by Elasticsearch's design
40
+ def initialize(name, field: nil, script: nil, size: nil, order: nil, missing: nil)
35
41
  if (field.present? && script.present?) || (field.blank? && script.blank?)
36
42
  raise ArgumentError, "Either 'field' or 'script' must be provided"
37
43
  end
@@ -42,13 +48,16 @@ module JayAPI
42
48
  @script = script
43
49
  @size = size
44
50
  @order = order
51
+ @missing = missing
45
52
  end
46
53
 
54
+ # rubocop:enable Metrics/ParameterLists
55
+
47
56
  # @return [self] A copy of the receiver.
48
57
  def clone
49
- self.class.new(name, field: field, script: script, size: size, order: order&.deep_dup).tap do |copy|
50
- copy.aggregations = aggregations.clone
51
- end
58
+ self.class.new(
59
+ name, field: field, script: script, size: size, order: order&.deep_dup, missing: missing
60
+ ).tap { |copy| copy.aggregations = aggregations.clone }
52
61
  end
53
62
 
54
63
  # @return [Hash] The Hash representation of the +Aggregation+.
@@ -60,7 +69,8 @@ module JayAPI
60
69
  field: field,
61
70
  size: size,
62
71
  script: script&.to_h,
63
- order: order
72
+ order: order,
73
+ missing: missing
64
74
  }.compact
65
75
  }
66
76
  end
@@ -15,20 +15,32 @@ module JayAPI
15
15
  # Information on this type of aggregation can be found here:
16
16
  # https://www.elastic.co/docs/reference/aggregations/search-aggregations-metrics-top-hits-aggregation
17
17
  class TopHits < ::JayAPI::Elasticsearch::QueryBuilder::Aggregations::Aggregation
18
- attr_reader :size
18
+ attr_reader :size, :sort, :_source
19
19
 
20
20
  # @param [String] name The name used by Elasticsearch to identify each
21
21
  # of the aggregations.
22
22
  # @param [String] size The number of hits that will be returned.
23
- def initialize(name, size:)
23
+ # @param [Hash] sort How to sort the documents to determine the top
24
+ # hits. When not specified the documents are sorted by the score of
25
+ # the main query.
26
+ # @param [FalseClass, String, Array<String>, Hash] _source Expression
27
+ # used for source filtering.
28
+ # @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-fields.html#source-filtering
29
+ # Elasticsearch's documentation for more information on what kind of
30
+ # expressions are allowed.
31
+ # rubocop:disable-next Lint/UnderscorePrefixedVariableName -- to match Elasticsearch's name
32
+ def initialize(name, size:, sort: nil, _source: nil)
24
33
  super(name)
25
34
 
26
35
  @size = size
36
+ @sort = sort
37
+ @_source = _source
27
38
  end
28
39
 
29
40
  # @return [self] A copy of the receiver.
30
41
  def clone
31
- copy = self.class.new(name, size: size)
42
+ optional_params = { sort: sort.deep_dup, _source: _source.deep_dup }.compact
43
+ copy = self.class.new(name, size: size, **optional_params)
32
44
  copy.aggregations = aggregations.clone
33
45
  copy
34
46
  end
@@ -39,8 +51,10 @@ module JayAPI
39
51
  super do
40
52
  {
41
53
  top_hits: {
42
- size: size
43
- }
54
+ size: size,
55
+ sort: sort.deep_dup,
56
+ _source: _source.deep_dup
57
+ }.compact
44
58
  }
45
59
  end
46
60
  end
@@ -32,11 +32,9 @@ module JayAPI
32
32
 
33
33
  # Adds a +terms+ type aggregation. For information about the parameters
34
34
  # @see JayAPI::Elasticsearch::QueryBuilder::Aggregations::Terms#initialize
35
- def terms(name, field: nil, script: nil, size: nil, order: nil)
35
+ def terms(name, **params)
36
36
  add(
37
- ::JayAPI::Elasticsearch::QueryBuilder::Aggregations::Terms.new(
38
- name, field: field, script: script, size: size, order: order
39
- )
37
+ ::JayAPI::Elasticsearch::QueryBuilder::Aggregations::Terms.new(name, **params)
40
38
  )
41
39
  end
42
40
 
@@ -72,8 +70,8 @@ module JayAPI
72
70
 
73
71
  # Adds a +top_hits+ type aggregation. For more information about the parameters
74
72
  # @see JayAPI::Elasticsearch::QueryBuilder::Aggregations::TopHits#initialize
75
- def top_hits(name, size:)
76
- add(::JayAPI::Elasticsearch::QueryBuilder::Aggregations::TopHits.new(name, size: size))
73
+ def top_hits(name, **params)
74
+ add(::JayAPI::Elasticsearch::QueryBuilder::Aggregations::TopHits.new(name, **params))
77
75
  end
78
76
 
79
77
  # Adds an +scripted_metric+ type aggregation. For information about the parameters
@@ -5,6 +5,7 @@ require_relative 'ids'
5
5
  require_relative 'match_all'
6
6
  require_relative 'match_none'
7
7
  require_relative 'match_phrase'
8
+ require_relative 'prefix'
8
9
  require_relative 'query_string'
9
10
  require_relative 'range'
10
11
  require_relative 'regexp'
@@ -31,6 +32,16 @@ module JayAPI
31
32
  self << ::JayAPI::Elasticsearch::QueryBuilder::QueryClauses::MatchPhrase.new(**params)
32
33
  end
33
34
 
35
+ # Adds a +JayAPI::Elasticsearch::QueryBuilder::QueryClauses::Prefix+
36
+ # clause to the Query Clauses set.
37
+ # @param [Hash] params The parameters for the +Prefix+ class.
38
+ # @return [self] Returns itself so that other methods can be chained.
39
+ # @raise [JayAPI::Elasticsearch::QueryBuilder::Errors::QueryBuilderError]
40
+ # If an error occurs when trying to add the query clause to the set.
41
+ def prefix(**params)
42
+ self << ::JayAPI::Elasticsearch::QueryBuilder::QueryClauses::Prefix.new(**params)
43
+ end
44
+
34
45
  # Adds a +JayAPI::Elasticsearch::QueryBuilder::QueryClauses::QueryString+
35
46
  # clause to the Query Clauses set.
36
47
  # @param [Hash] params The parameters for the +QueryString+ class
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'query_clause'
4
+
5
+ module JayAPI
6
+ module Elasticsearch
7
+ class QueryBuilder
8
+ class QueryClauses
9
+ # Represents a +Prefix+ query in Elasticsearch
10
+ # More information about this type of query can be found here:
11
+ # https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-prefix-query.html
12
+ class Prefix < ::JayAPI::Elasticsearch::QueryBuilder::QueryClauses::QueryClause
13
+ attr_reader :field, :value
14
+
15
+ # @param [String, Symbol] field The field where the prefix query
16
+ # should be applied.
17
+ # @param [String] value The prefix to be found in +field+
18
+ def initialize(field:, value:)
19
+ super()
20
+ @field = field
21
+ @value = value
22
+ end
23
+
24
+ # @return [Hash] The Hash that represents this query (in
25
+ # Elasticsearch's format)
26
+ def to_h
27
+ {
28
+ prefix: {
29
+ field => {
30
+ value: value
31
+ }
32
+ }
33
+ }
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -24,7 +24,8 @@ module JayAPI
24
24
  # @param [JayAPI::Elasticsearch::Indexable] index The Elasticsearch
25
25
  # index or indexes over which the query should be performed.
26
26
  # @param [Hash] query The query that produced the results.
27
- # @param [JayAPI::Elasticsearch::Results] response An object containing Docs retrieved from Elasticsearch.
27
+ # @param [JayAPI::Elasticsearch::Response] response An object containing
28
+ # Docs retrieved from Elasticsearch.
28
29
  # @param [JayAPI::Elasticsearch::BatchCounter] batch_counter An object keeping track of the current batch.
29
30
  def initialize(index:, query:, response:, batch_counter: nil)
30
31
  @index = index
@@ -2,5 +2,5 @@
2
2
 
3
3
  module JayAPI
4
4
  # JayAPI gem's semantic version
5
- VERSION = '29.9.0'
5
+ VERSION = '29.11.0'
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jay_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 29.9.0
4
+ version: 29.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Accenture-Industry X
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2026-08-04 00:00:00.000000000 Z
12
+ date: 2026-09-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -169,6 +169,7 @@ files:
169
169
  - lib/jay_api/elasticsearch/query_builder/query_clauses/match_none.rb
170
170
  - lib/jay_api/elasticsearch/query_builder/query_clauses/match_phrase.rb
171
171
  - lib/jay_api/elasticsearch/query_builder/query_clauses/negator.rb
172
+ - lib/jay_api/elasticsearch/query_builder/query_clauses/prefix.rb
172
173
  - lib/jay_api/elasticsearch/query_builder/query_clauses/query_clause.rb
173
174
  - lib/jay_api/elasticsearch/query_builder/query_clauses/query_string.rb
174
175
  - lib/jay_api/elasticsearch/query_builder/query_clauses/range.rb