module Goodyear::QueryMethods
Public Instance Methods
count()
click to toggle source
# File lib/goodyear/query_methods.rb, line 72 def count search_type 'count' fetch.total end
fetch()
click to toggle source
# 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
perform()
click to toggle source
# 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
Also aliased as: to_query
reset_query()
click to toggle source
# File lib/goodyear/query_methods.rb, line 99 def reset_query clean end
results()
click to toggle source
# File lib/goodyear/query_methods.rb, line 77 def results fetch.results end
routing(r)
click to toggle source
# File lib/goodyear/query_methods.rb, line 81 def routing(r) @_search_options ||= {} @_search_options.merge! routing: r self end
scope(name, scope_options = {})
click to toggle source
# 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)
click to toggle source
# File lib/goodyear/query_methods.rb, line 61 def search_options(options) @_search_options = options self end
search_type(type)
click to toggle source
# File lib/goodyear/query_methods.rb, line 66 def search_type(type) @_search_options ||= {} @_search_options.merge! search_type: type self end
Private Instance Methods
clean()
click to toggle source
# File lib/goodyear/query_methods.rb, line 105 def clean @_fields = [] @_and = [] @_size = nil @_sort = [] @_or = [] @_facets = [] @_filters = [] @_highlights = [] @query_segments = [] @_query_filters = nil end
construct_query()
click to toggle source
# File lib/goodyear/query_methods.rb, line 118 def construct_query @query_segments ||= [] @query_segments << @_and @_query = @query_segments.collect do |segment| next if segment.nil? segment.uniq.join(" AND ") end.join(" OR ") end