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 +4 -4
- data/README.md +10 -7
- data/lib/caoutsearch/filter/date.rb +0 -19
- data/lib/caoutsearch/search/batch/search_after.rb +1 -0
- data/lib/caoutsearch/search/internal_dsl.rb +3 -3
- data/lib/caoutsearch/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9a9f19fbbee99086c07a66881e1b3d5f5df90f4dc06d32ce4a4d4dfc323a85bb
|
4
|
+
data.tar.gz: cf8736b55478e95f3e98a529d9e2f4102de8a59921108bf99703d9c6fe742a54
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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",
|
@@ -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,
|
72
|
-
raise ArgumentError, "has_aggregation accepts
|
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,
|
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)
|
data/lib/caoutsearch/version.rb
CHANGED
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.
|
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:
|
12
|
+
date: 2023-01-30 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|