Class: Arel::Collectors::ElasticsearchQuery

Inherits:
ElasticsearchRecord::Query show all
Defined in:
lib/arel/collectors/elasticsearch_query.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeElasticsearchQuery

Returns a new instance of ElasticsearchQuery.



15
16
17
18
19
20
21
# File 'lib/arel/collectors/elasticsearch_query.rb', line 15

def initialize
  # force initialize a body as hash
  super(body: {})

  # @binds = []
  @bind_index = 1
end

Instance Attribute Details

#bind_indexObject (readonly)

returns the current bind index (default: 1)



13
14
15
# File 'lib/arel/collectors/elasticsearch_query.rb', line 13

def bind_index
  @bind_index
end

#preparableObject

required for ActiveRecord



10
11
12
# File 'lib/arel/collectors/elasticsearch_query.rb', line 10

def preparable
  @preparable
end

Instance Method Details

#<<(claim) ⇒ Object



68
69
70
# File 'lib/arel/collectors/elasticsearch_query.rb', line 68

def <<(claim)
  self.claim(claim[0], *claim[1])
end

#add_bind(bind, &block) ⇒ Object

IMPORTANT: For SQL defaults (see @ Arel::Collectors::SubstituteBinds) a value will +not+ be directly assigned (see @ Arel::Visitors::ToSql#visit_Arel_Nodes_HomogeneousIn). instead it will be send as bind and then re-delegated to the SQL collector.

This only works for linear SQL-queries and not nested Hashes (otherwise we have to collect those binds, and replace them afterwards).

This will be ignored by the ElasticsearchQuery collector, but supports statement caches on the other side (see @ ActiveRecord::StatementCache::PartialQueryCollector)



86
87
88
89
90
# File 'lib/arel/collectors/elasticsearch_query.rb', line 86

def add_bind(bind, &block)
  @bind_index += 1

  self
end

#add_binds(binds, proc_for_binds = nil, &block) ⇒ Object

See Also:



93
94
95
96
# File 'lib/arel/collectors/elasticsearch_query.rb', line 93

def add_binds(binds, proc_for_binds = nil, &block)
  @bind_index += binds.size
  self
end

#claim(action, *args) ⇒ Object

send a proposal to this query

Parameters:

  • action (Symbol)
    • the claim action
  • args (Array)
    • args to claim


26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/arel/collectors/elasticsearch_query.rb', line 26

def claim(action, *args)
  case action
  when :refresh
    # change the refresh state
    @refresh = args[0]
  when :timeout
    # change the timeout
    @timeout = args[0]
  when :index
    # change the index name
    @index = args[0]
  when :type
    # change the query type
    @type = args[0]
  when :status
    # change the query status
    @status = args[0]
  when :columns
    # change the query columns
    @columns = args[0]
  when :arguments
    # change the query arguments
    @arguments = args[0]
  when :argument
    # adds / sets any argument
    if args.length == 2
      @arguments[args[0]] = args[1]
    else
      # should be a hash
      @arguments.merge!(args[0])
    end
  when :body
    # set the body var
    @body = args[0]
  when :assign
    # calls a assign on the body
    assign(*args)
  else
    raise "Unsupported claim action: #{action}"
  end
end

#valueObject

used by the +Arel::Visitors::Elasticsearch#compile+ method (and default Arel visitors)



73
74
75
# File 'lib/arel/collectors/elasticsearch_query.rb', line 73

def value
  self
end