Module: Elastics::Scope::VarsMethods

Includes:
Utils
Included in:
Elastics::Scope
Defined in:
lib/elastics/scope/vars_methods.rb

Instance Method Summary collapse

Instance Method Details

#fields(*value) ⇒ Object

the fields that you want to retrieve (limiting the size of the response) the returned records will be frozen (for Elastics::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/elastics/scope/vars_methods.rb', line 24

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

#highlight(hash) ⇒ Object



72
73
74
# File 'lib/elastics/scope/vars_methods.rb', line 72

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

#index(val) ⇒ Object



53
54
55
# File 'lib/elastics/scope/vars_methods.rb', line 53

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

#metricsObject



76
77
78
# File 'lib/elastics/scope/vars_methods.rb', line 76

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



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

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

#params(value) ⇒ Object

the standard :params variable



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

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

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



7
8
9
10
# File 'lib/elastics/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


63
64
65
66
67
68
69
70
# File 'lib/elastics/scope/vars_methods.rb', line 63

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



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

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/elastics/scope/vars_methods.rb', line 17

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

#source(*value) ⇒ Object Also known as: _source



28
29
30
# File 'lib/elastics/scope/vars_methods.rb', line 28

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

#type(val) ⇒ Object



57
58
59
# File 'lib/elastics/scope/vars_methods.rb', line 57

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

#variables(*variables) ⇒ Object

meaningful alias of deep_merge



49
50
51
# File 'lib/elastics/scope/vars_methods.rb', line 49

def variables(*variables)
  deep_merge *variables
end