Class: MmEsSearch::Models::VirtualFieldSort

Inherits:
AbstractSortModel show all
Defined in:
lib/mm_es_search/models/virtual_field_sort.rb

Instance Method Summary collapse

Instance Method Details

#sort_scriptObject



39
40
41
42
43
44
45
46
47
48
# File 'lib/mm_es_search/models/virtual_field_sort.rb', line 39

def sort_script
  sort_field = self.sort_field
  mod_path = path.gsub(/\.[0-9]+/,'')
  case direction    
  when "asc", "ascending", nil
    "0 - doc['#{mod_path}.#{sort_field}'].value"
  when "desc", "descending"
    "0 + doc['#{mod_path}.#{sort_field}'].value"
  end
end

#to_es_queryObject



9
10
11
# File 'lib/mm_es_search/models/virtual_field_sort.rb', line 9

def to_es_query
  to_query.to_es_query
end

#to_filterObject



28
29
30
31
32
33
34
35
36
37
# File 'lib/mm_es_search/models/virtual_field_sort.rb', line 28

def to_filter
  NestedFilter.new(
    :path => path,
    :query => TermFilter.new(
      :path => path,
      :field => field,
      :value => virtual_field
    )
  )
end

#to_queryObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/mm_es_search/models/virtual_field_sort.rb', line 13

def to_query
  NestedQuery.new(
    :score_mode => "max",
    :path => path,
    :query => CustomScoreQuery.new(
      :script => sort_script,
      :query => TermQuery.new(
        :path => path,
        :field => field,
        :value => virtual_field
      )
    )
  )
end