caoutsearch 0.0.3 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f16ab6e645d648ff48bb24e46cab2134f8700bfc6974a16da81fad021878f3e3
4
- data.tar.gz: 31057dc62f3f29e4d227baa57cec3683713a73a686547a5119a58b75c0554373
3
+ metadata.gz: 9a9f19fbbee99086c07a66881e1b3d5f5df90f4dc06d32ce4a4d4dfc323a85bb
4
+ data.tar.gz: cf8736b55478e95f3e98a529d9e2f4102de8a59921108bf99703d9c6fe742a54
5
5
  SHA512:
6
- metadata.gz: bae5aa7e329a079816d1951dbbdf60df21aac2d2593ec68bd72a4fa1236100c93946dfb55e3b2fe75b8cc1308124d21704ab6c8554a40c5c97feda8c9b6acd36
7
- data.tar.gz: b3a4d9679db2a2c327b6bf1845be392cfce6bb514823816cf7f74f04254dfd92b55787f99530b3b759f1ccee06a5a8f253cb9c6cd08ce432170b77081e6987f5
6
+ metadata.gz: 3ee219e96b1b77bbdea6b20a91bb252915b2f557c82924892e67d9ca6d08caf7013f8a8ac05852375f9821cda4e7fb0ba23226ff04943e03a4a7f2d16dd80bf4
7
+ data.tar.gz: d154e911d74f71f14540d551ead74a9452770660a8be4b991a73d2d2dbed3a206274b51a30b1c7090587e6bbdea389729104af293fd6f542211ae7fd952ec12a
data/README.md CHANGED
@@ -187,14 +187,15 @@ You can define simple to complex aggregations.
187
187
 
188
188
  ````ruby
189
189
  class ArticleSearch < Caoutsearch::Search::Base
190
- has_aggregation :view_count, sum: { field: :view_count }
191
- has_aggregation :popular_tags,
190
+ has_aggregation :view_count, { sum: { field: :view_count } }
191
+ has_aggregation :popular_tags, {
192
192
  filter: { term: { published: true } },
193
193
  aggs: {
194
194
  published: {
195
195
  terms: { field: :tags, size: 10 }
196
196
  }
197
197
  }
198
+ }
198
199
  end
199
200
  ````
200
201
 
@@ -314,8 +315,8 @@ You can also use transformations to combine multiple aggregations:
314
315
 
315
316
  ````ruby
316
317
  class ArticleSearch < Caoutsearch::Search::Base
317
- has_aggregation :blog_count, filter: { term: { category: "blog" } }
318
- has_aggregation :archives_count, filter: { term: { archived: true } }
318
+ has_aggregation :blog_count, { filter: { term: { category: "blog" } } }
319
+ has_aggregation :archives_count, { filter: { term: { archived: true } } }
319
320
 
320
321
  transform_aggregation :stats, from: %i[blog_count archives_count] do |aggs|
321
322
  {
@@ -335,9 +336,10 @@ This is also usefull to unify the API between different search engines:
335
336
 
336
337
  ````ruby
337
338
  class ArticleSearch < Caoutsearch::Search::Base
338
- has_aggregation :popular_tags,
339
+ has_aggregation :popular_tags, {
339
340
  filter: { term: { published: true } },
340
341
  aggs: { published: { terms: { field: :tags, size: 10 } } }
342
+ }
341
343
 
342
344
  transform_aggregation :popular_tags do |aggs|
343
345
  aggs.dig(:popular_tags, :published, :buckets).pluck(:key)
@@ -345,8 +347,9 @@ class ArticleSearch < Caoutsearch::Search::Base
345
347
  end
346
348
 
347
349
  class TagSearch < Caoutsearch::Search::Base
348
- has_aggregation :popular_tags,
350
+ has_aggregation :popular_tags, {
349
351
  terms: { field: "label", size: 20, order: { used_count: "desc" } }
352
+ }
350
353
 
351
354
  transform_aggregation :popular_tags do |aggs|
352
355
  aggs.dig(:popular_tags, :buckets).pluck(:key)
@@ -366,7 +369,7 @@ Transformations are performed on demand and result is memorized. That means:
366
369
 
367
370
  ````ruby
368
371
  class ArticleSearch < Caoutsearch::Search::Base
369
- has_aggregation :popular_tags, …
372
+ has_aggregation :popular_tags, {}
370
373
 
371
374
  transform_aggregation :popular_tags do |aggs|
372
375
  tags = aggs.dig(:popular_tags, :published, :buckets).pluck(:key)
@@ -27,8 +27,6 @@ module Caoutsearch
27
27
  build_range_query(input)
28
28
  when ::Hash
29
29
  case input
30
- in { operator:, value:, **other}
31
- build_legacy_range_query_from_hash(input)
32
30
  in { between: dates }
33
31
  build_range_query(dates)
34
32
  else
@@ -61,23 +59,6 @@ module Caoutsearch
61
59
  query
62
60
  end
63
61
 
64
- def build_legacy_range_query_from_hash(input)
65
- ActiveSupport::Deprecation.warn("This form of hash to search for dates will be removed")
66
- operator, value, unit = input.values_at(:operator, :value, :unit)
67
-
68
- case operator
69
- when "less_than"
70
- {range: {key => {gte: cast_date(value, unit)}}}
71
- when "greater_than"
72
- {range: {key => {lt: cast_date(value, unit)}}}
73
- when "between"
74
- dates = value.map { |v| cast_date(v, unit) }.sort
75
- {range: {key => {gte: dates[0], lt: dates[1]}}}
76
- else
77
- raise ArgumentError, "unknown operator #{operator.inspect} in #{value.inspect}"
78
- end
79
- end
80
-
81
62
  RANGE_OPERATORS = {
82
63
  "less_than" => "lt",
83
64
  "less_than_or_equal" => "lte",
@@ -16,6 +16,7 @@ module Caoutsearch
16
16
  }
17
17
  )
18
18
  }
19
+ request_payload[:body][:sort] ||= [:_shard_doc]
19
20
 
20
21
  total = nil
21
22
  progress = 0
@@ -68,11 +68,11 @@ module Caoutsearch
68
68
  sort(new_name) { |direction| sort_by(old_name, direction) }
69
69
  end
70
70
 
71
- def has_aggregation(name, **options, &block)
72
- raise ArgumentError, "has_aggregation accepts options or block but not both" if block && options.any?
71
+ def has_aggregation(name, definition = {}, &block)
72
+ raise ArgumentError, "has_aggregation accepts Hash definition or block but not both" if block && definition.any?
73
73
 
74
74
  self.aggregations = aggregations.dup
75
- aggregations[name.to_s] = Caoutsearch::Search::DSL::Item.new(name, options, &block)
75
+ aggregations[name.to_s] = Caoutsearch::Search::DSL::Item.new(name, definition, &block)
76
76
  end
77
77
 
78
78
  def alias_aggregation(new_name, old_name)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Caoutsearch
4
- VERSION = "0.0.3"
4
+ VERSION = "0.0.5"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: caoutsearch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Savater Sebastien
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2022-12-21 00:00:00.000000000 Z
12
+ date: 2023-01-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport