Class: ElasticQueue::Query
- Inherits:
-
Object
- Object
- ElasticQueue::Query
show all
- Defined in:
- lib/elastic_queue/query.rb
Instance Method Summary
collapse
Constructor Details
#initialize(queue, options = {}) ⇒ Query
Returns a new instance of Query.
6
7
8
9
|
# File 'lib/elastic_queue/query.rb', line 6
def initialize(queue, options = {})
@queue = queue
@options = QueryOptions.new(options)
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
this allows you to chain scopes the 2+ scopes in the chain will be called on a query object and not on the base object
84
85
86
87
88
89
|
# File 'lib/elastic_queue/query.rb', line 84
def method_missing(method, *args, &block)
if @queue.respond_to?(method)
proc = @queue.scopes[method]
instance_exec *args, &proc
end
end
|
Instance Method Details
#all ⇒ Object
56
57
58
|
# File 'lib/elastic_queue/query.rb', line 56
def all
Results.new(@queue, execute, @options).instantiated_queue_items
end
|
#body ⇒ Object
38
39
40
|
# File 'lib/elastic_queue/query.rb', line 38
def body
@options.body
end
|
#count ⇒ Object
65
66
67
|
# File 'lib/elastic_queue/query.rb', line 65
def count
execute(count: true, paginate: false)[:hits][:total].to_i
end
|
#filter(options) ⇒ Object
11
12
13
14
|
# File 'lib/elastic_queue/query.rb', line 11
def filter(options)
@options.add_filter(options)
self
end
|
#filters ⇒ Object
16
17
18
|
# File 'lib/elastic_queue/query.rb', line 16
def filters
@options.filters
end
|
#ids ⇒ Object
return just the ids of the records (useful when combined with SQL queries)
61
62
63
|
# File 'lib/elastic_queue/query.rb', line 61
def ids
execute[:hits][:hits].map { |h| h[:_source][:id] }
end
|
#page=(page) ⇒ Object
TODO: remove if not using, add per_page if using
52
53
54
|
# File 'lib/elastic_queue/query.rb', line 52
def page=(page)
@options.page = (page)
end
|
#paginate(options = {}) ⇒ Object
46
47
48
49
|
# File 'lib/elastic_queue/query.rb', line 46
def paginate(options = {})
options.each { |k, v| @options.send("#{k}=", v) }
Results.new(@queue, execute(paginate: true), @options).paginate
end
|
#percolator_body ⇒ Object
42
43
44
|
# File 'lib/elastic_queue/query.rb', line 42
def percolator_body
@options.percolator_body
end
|
#search(string) ⇒ Object
29
30
31
32
|
# File 'lib/elastic_queue/query.rb', line 29
def search(string)
@options.add_search(string)
self
end
|
#searches ⇒ Object
34
35
36
|
# File 'lib/elastic_queue/query.rb', line 34
def searches
@options.search
end
|
#sort(options) ⇒ Object
20
21
22
23
|
# File 'lib/elastic_queue/query.rb', line 20
def sort(options)
@options.add_sort(options)
self
end
|
#sorts ⇒ Object
25
26
27
|
# File 'lib/elastic_queue/query.rb', line 25
def sorts
@options.sorts
end
|