@@ -19,27 +19,71 @@ module Elasticsearch
19
19
module DSL
20
20
module Search
21
21
22
+ # Wraps the `collapse` part of a search definition
23
+ #
24
+ # @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-collapse.html
25
+ #
26
+ # @since 0.1.9
22
27
class Collapse
23
28
include BaseComponent
24
29
30
+ # Initialize the field collapse definition.
31
+ #
32
+ # @param field [ String, Symbol ] The name of the field.
33
+ #
34
+ # @since 0.1.9
25
35
def initialize ( field , &block )
26
36
@hash = { field : field }
27
37
@block = block
28
38
end
29
39
30
- def inner_hits ( name = nil , &block )
31
- if name
32
- @inner_hits = InnerHits . new ( name , &block )
33
- self
34
- else
35
- @inner_hits
36
- end
40
+ # Create an inner_hits definition.
41
+ #
42
+ # @example
43
+ # collapse :user
44
+ # inner_hits 'last_tweet' do
45
+ # size 10
46
+ # from 5
47
+ # sort do
48
+ # by :date, order: 'desc'
49
+ # by :likes, order: 'asc'
50
+ # end
51
+ # end
52
+ # end
53
+ #
54
+ # @return self
55
+ #
56
+ # @since 0.1.9
57
+ def inner_hits ( name , &block )
58
+ @inner_hits = InnerHits . new ( name , &block )
59
+ self
37
60
end
38
61
62
+ # Specify the max_concurrent_group_searches setting on the collapse definition.
63
+ #
64
+ # @example
65
+ # collapse :user
66
+ # max_concurrent_group_searches 4
67
+ # end
68
+ #
69
+ # @return self.
70
+ #
71
+ # @since 0.1.9
39
72
def max_concurrent_group_searches ( max )
40
73
@hash [ :max_concurrent_group_searches ] = max
74
+ self
41
75
end
42
76
77
+ # Convert the definition to a hash, to be used in a search request.
78
+ #
79
+ # @example
80
+ # definition = collapse :user
81
+ # max_concurrent_group_searches 4
82
+ # end
83
+ #
84
+ # @return [ Hash ] The collapse clause as a hash.
85
+ #
86
+ # @since 0.1.9
43
87
def to_hash
44
88
call
45
89
@hash [ :inner_hits ] = @inner_hits . to_hash if @inner_hits
0 commit comments