Module: Goodyear::QueryMethods
Instance Method Summary
collapse
Methods included from Enumerable
#collect, #each
Methods included from QueryCache
#cache_query, #store
#filter, #has_field?, #query_filter
#facet
#or
#all, #fields, #first, #highlight, #last, #size, #sort, #where
Instance Method Details
#count ⇒ Object
72
73
74
75
|
# File 'lib/goodyear/query_methods.rb', line 72
def count
search_type 'count'
fetch.total
end
|
#fetch ⇒ Object
18
19
20
21
22
23
24
25
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
|
# File 'lib/goodyear/query_methods.rb', line 18
def fetch
es = self.perform
options = {wrapper: self, type: document_type}
options.merge!( @_search_options ) unless @_search_options.nil?
@_search_options = nil
tire = Tire::Search::Search.new(self.index_name, options)
if es.query_filters.empty?
tire.query { string es.query } unless es.query.blank?
else
tire.query do
filtered do
query { string es.query } unless es.query.blank?
es.query_filters.each { |f| filter(f[:name], f[:options]) }
end
end
end
tire.sort{ by *es.sort } unless es.sort.blank?
tire.size( es.size ) unless es.size.nil?
tire.fields( es.fields ) unless es.fields.empty?
tire.highlight( es.highlights ) unless es.highlights.empty?
es.filters.each do |f|
tire.filter(f[:name], f[:args], &f[:l])
end
es.facets.each do |f|
tire.facet(f[:name], f[:args], &f[:l] )
end
cache_query(tire.to_curl) { tire.version(true).results }
end
|
54
55
56
57
58
59
|
# File 'lib/goodyear/query_methods.rb', line 54
def perform
construct_query
esq = Query.new(@_query, @_fields, @_size, @_sort, @_highlights, @_facets, @_filters, @_query_filters)
clean
return esq
end
|
#reset_query ⇒ Object
99
100
101
|
# File 'lib/goodyear/query_methods.rb', line 99
def reset_query
clean
end
|
#results ⇒ Object
77
78
79
|
# File 'lib/goodyear/query_methods.rb', line 77
def results
fetch.results
end
|
#routing(r) ⇒ Object
81
82
83
84
85
|
# File 'lib/goodyear/query_methods.rb', line 81
def routing(r)
@_search_options ||= {}
@_search_options.merge! routing: r
self
end
|
#scope(name, scope_options = {}) ⇒ Object
87
88
89
90
91
92
93
94
95
|
# File 'lib/goodyear/query_methods.rb', line 87
def scope(name, scope_options = {})
name = name.to_sym
scope_proc = lambda do |*args|
options = scope_options.respond_to?(:call) ? scope_options.call(*args) : scope_options
end
singleton_class.send(:define_method, name, &scope_proc)
end
|
#search_options(options) ⇒ Object
61
62
63
64
|
# File 'lib/goodyear/query_methods.rb', line 61
def search_options(options)
@_search_options = options
self
end
|
#search_type(type) ⇒ Object
66
67
68
69
70
|
# File 'lib/goodyear/query_methods.rb', line 66
def search_type(type)
@_search_options ||= {}
@_search_options.merge! search_type: type
self
end
|