Class: Sort::ScriptSortBuilder

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

Defined Under Namespace

Classes: ScriptSortTypes

Constant Summary collapse

NAME =
'_script'

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(script:, type:) ⇒ ScriptSortBuilder

@params:

script: Script used in this sort.
type: Script sort type used in this sort, can be (number, string).
nested_sort: Nested path within current object.
sort_mode: Defines which distance to use for sorting in the case a document contains multiple values.


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

def initialize script:, type:
  @script = script
  @type = type.script_sort_type
  @nested_sort = nil
  @sort_mode = nil
end

Instance Method Details

#nested_sort(nested_sort) ⇒ Object

sets nested_sort



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

def nested_sort nested_sort
  @nested_sort = nested_sort
  return self
end

#nested_sort_exprObject

returns nested_sort



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

def nested_sort_expr
  return @nested_sort
end

#queryObject



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

def query
  query = {}
  script_query = self.common_query
  script_query[:script] = @script.settings
  script_query[:type] = @type
  script_query[:nested] = @nested_sort.query if @nested_sort.present?
  script_sort[:sort_mode] = @sort_mode if @sort_mode.present?
  query[name.intern] = script_query
  return query
end

#script_exprObject

returns script



35
36
37
# File 'lib/sort/script_sort_builder.rb', line 35

def script_expr
  return @script
end

#sort_mode(sort_mode) ⇒ Object

sets sort_mode



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

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

#sort_mode_exprObject

returns sort_mode



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

def sort_mode_expr
  return @sort_mode
end

#type_exprObject

returns type



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

def type_expr
  return @type
end