Skip to content

Commit b187041

Browse files
committed
[DSL] Add documentation for Collapse search clause definition
1 parent 700ea70 commit b187041

File tree

1 file changed

+51
-7
lines changed

1 file changed

+51
-7
lines changed

lib/elasticsearch/dsl/search/queries/collapse.rb

+51-7
Original file line numberDiff line numberDiff line change
@@ -19,27 +19,71 @@ module Elasticsearch
1919
module DSL
2020
module Search
2121

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
2227
class Collapse
2328
include BaseComponent
2429

30+
# Initialize the field collapse definition.
31+
#
32+
# @param field [ String, Symbol ] The name of the field.
33+
#
34+
# @since 0.1.9
2535
def initialize(field, &block)
2636
@hash = { field: field }
2737
@block = block
2838
end
2939

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
3760
end
3861

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
3972
def max_concurrent_group_searches(max)
4073
@hash[:max_concurrent_group_searches] = max
74+
self
4175
end
4276

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
4387
def to_hash
4488
call
4589
@hash[:inner_hits] = @inner_hits.to_hash if @inner_hits

0 commit comments

Comments
 (0)