Class: Sort::FieldSortBuilder

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

Constant Summary collapse

NAME =
"field_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(field_name:) ⇒ FieldSortBuilder

Returns a new instance of FieldSortBuilder.



8
9
10
# File 'lib/sort/field_sort_builder.rb', line 8

def initialize field_name:
  @field_name = field_name
end

Instance Method Details

#field_name_exprObject

returns field_name



24
25
26
# File 'lib/sort/field_sort_builder.rb', line 24

def field_name_expr
  return @field_name
end

#missing(missing) ⇒ Object

sets missing



44
45
46
47
# File 'lib/sort/field_sort_builder.rb', line 44

def missing missing
  @missing = missing.is_a?(Missing) ? missing.missing : missing
  return self
end

#missing_exprObject

returns missing



40
41
42
# File 'lib/sort/field_sort_builder.rb', line 40

def missing_expr
  return @missing
end

#nested_sort(nested_sort) ⇒ Object

sets nested_sort

Raises:

  • (ArgumentError)


33
34
35
36
37
# File 'lib/sort/field_sort_builder.rb', line 33

def nested_sort nested_sort
  raise ArgumentError.new("pass a nested query object") if nested_sort.name != "nested"
  @nested_sort = nested_sort
  return self
end

#nested_sort_exprObject

returns nested_sort



29
30
31
# File 'lib/sort/field_sort_builder.rb', line 29

def nested_sort_expr
  return @nested_sort
end

#queryObject



12
13
14
15
16
17
18
19
20
21
# File 'lib/sort/field_sort_builder.rb', line 12

def query
  query = {}
  field_query = self.common_query
  field_query[:mode] = @sort_mode if @sort_mode.present?
  field_query[:missing] = @missing if @missing.present?
  field_query[:unmapped_type] = @unmapped_type if @unmapped_type.present?
  field_query[:nested] = @nested_sort.query[:nested] if @nested_sort.present?
  query[@field_name.intern] = field_query
  return query
end

#sort_mode(sort_mode) ⇒ Object

sets sort_mode



54
55
56
57
# File 'lib/sort/field_sort_builder.rb', line 54

def sort_mode sort_mode
  @sort_mode = sort_mode.sort_mode
  return self
end

#sort_mode_exprObject

returns sort_mode



50
51
52
# File 'lib/sort/field_sort_builder.rb', line 50

def sort_mode_expr
  return @sort_mode
end

#unmapped_type(unmapped_type) ⇒ Object

sets unmapped_type



64
65
66
67
# File 'lib/sort/field_sort_builder.rb', line 64

def unmapped_type unmapped_type
  @unmapped_type = unmapped_type
  return self
end

#unmapped_type_exprObject

returns unmapped_type



60
61
62
# File 'lib/sort/field_sort_builder.rb', line 60

def unmapped_type_expr
  return  @unmapped_type
end