Module: Flex::Scope::VarsMethods

Includes:
Utils
Included in:
Flex::Scope
Defined in:
lib/flex/scope/vars_methods.rb

Instance Method Summary collapse

Instance Method Details

#facets(hash) ⇒ Object



67
68
69
# File 'lib/flex/scope/vars_methods.rb', line 67

def facets(hash)
  deep_merge :facets => hash
end

#fields(*value) ⇒ Object

the fields that you want to retrieve (limiting the size of the response) the returned records will be frozen (for Flex::ActiveModel objects), and the missing fields will be nil pass an array eg fields.([:field_one, :field_two]) or a list of fields e.g. fields(:field_one, :field_two)



24
25
26
# File 'lib/flex/scope/vars_methods.rb', line 24

def fields(*value)
  deep_merge :params => {:fields => array_value(value)}
end

#highlight(hash) ⇒ Object



71
72
73
# File 'lib/flex/scope/vars_methods.rb', line 71

def highlight(hash)
  deep_merge :highlight => hash
end

#index(val) ⇒ Object



48
49
50
# File 'lib/flex/scope/vars_methods.rb', line 48

def index(val)
  deep_merge :index => val
end

#metricsObject



75
76
77
# File 'lib/flex/scope/vars_methods.rb', line 75

def metrics
  deep_merge :params => {:search_type => 'count'}
end

#page(value) ⇒ Object

sets the :from param so it will return the nth page of size :size



34
35
36
# File 'lib/flex/scope/vars_methods.rb', line 34

def page(value)
  deep_merge :page => value || 1
end

#params(value) ⇒ Object

the standard :params variable



39
40
41
# File 'lib/flex/scope/vars_methods.rb', line 39

def params(value)
  deep_merge :params => value
end

#query_string(q) ⇒ Object Also known as: query



7
8
9
10
# File 'lib/flex/scope/vars_methods.rb', line 7

def query_string(q)
  hash = q.is_a?(Hash) ? q : {:query => q}
  deep_merge :cleanable_query => hash
end

#script_fields(hash) ⇒ Object

script_fields(:my_field => ‘script …’, # simpler form

:my_other_field => {:script => 'script ...', ...}) # ES API


58
59
60
61
62
63
64
65
# File 'lib/flex/scope/vars_methods.rb', line 58

def script_fields(hash)
  hash.keys.each do |k|
    v = hash[k]
    hash[k] = {:script => v} unless v.is_a?(Hash)
    hash[k][:script].gsub!(/\n+\s*/,' ')
  end
  deep_merge :script_fields => hash
end

#size(value) ⇒ Object

limits the size of the retrieved hits



29
30
31
# File 'lib/flex/scope/vars_methods.rb', line 29

def size(value)
  deep_merge :params => {:size => value}
end

#sort(*value) ⇒ Object

accepts one or an array or a list of sort structures documented at www.elasticsearch.org/guide/reference/api/search/sort.html doesn’t probably support the multiple hash form, but you can pass an hash as single argument or an array or list of hashes



17
18
19
# File 'lib/flex/scope/vars_methods.rb', line 17

def sort(*value)
  deep_merge :sort => array_value(value)
end

#type(val) ⇒ Object



52
53
54
# File 'lib/flex/scope/vars_methods.rb', line 52

def type(val)
  deep_merge :type => val
end

#variables(*variables) ⇒ Object

meaningful alias of deep_merge



44
45
46
# File 'lib/flex/scope/vars_methods.rb', line 44

def variables(*variables)
  deep_merge *variables
end