Class: Sort::NestedSortBuilder

Inherits:
SortBuilder show all
Defined in:
lib/sort/nested_sort_builder.rb

Constant Summary collapse

NAME =
'nested_sort'

Instance Method Summary collapse

Methods inherited from SortBuilder

#common_query, #order, #order_expr

Methods included from AbstractSortBuilder

#doEquals​?, #name

Methods included from AttributesReader

#attributes

Constructor Details

#initialize(path:) ⇒ NestedSortBuilder

@params:

filter: A filter that the inner objects inside the nested path should match with in order for its field values to be taken into account by sorting.
max_children: The maximum number of children to consider per root document when picking the sort value.
nested_sort: Same as top-level nested but applies to another nested path within the current nested object.
path: Defines on which nested object to sort. The actual sort field must be a direct field inside this nested object.


16
17
18
19
20
21
# File 'lib/sort/nested_sort_builder.rb', line 16

def initialize path:
  @path = path
  @filter = nil
  @max_children = nil
  @nested_sort = nil
end

Instance Method Details

#filter(filter) ⇒ Object

sets filter



42
43
44
45
# File 'lib/sort/nested_sort_builder.rb', line 42

def filter filter
  @filter = filter
  return self
end

#filter_exprObject

returns filter



38
39
40
# File 'lib/sort/nested_sort_builder.rb', line 38

def filter_expr
  return @filter
end

#max_children(max_children) ⇒ Object

sets max_children



52
53
54
55
# File 'lib/sort/nested_sort_builder.rb', line 52

def max_children max_children
  @max_children = max_children
  return self
end

#max_children_exprObject

returns max_children



48
49
50
# File 'lib/sort/nested_sort_builder.rb', line 48

def max_children_expr
  return @max_children
end

#nested_sort(nested_sort) ⇒ Object

sets nested_sort



62
63
64
65
# File 'lib/sort/nested_sort_builder.rb', line 62

def nested_sort nested_sort
  @nested_sort = nested_sort
  return self
end

#nested_sort_exprObject

returns nested_sort



58
59
60
# File 'lib/sort/nested_sort_builder.rb', line 58

def nested_sort_expr
  return @nested_sort
end

#path_exprObject

returns path



33
34
35
# File 'lib/sort/nested_sort_builder.rb', line 33

def path_expr
  return @path
end

#queryObject



23
24
25
26
27
28
29
30
# File 'lib/sort/nested_sort_builder.rb', line 23

def query
  query = self.common_query
  query[:path] = @path
  query[:filter] = @filter.query if @filter.present?
  query[:nested] = @nested_sort.query if @nested_sort.present?
  query[:max_children] = @max_children if @max_children.present?
  return query
end