# File lib/thinking_sphinx/search.rb, line 24 def initialize(query = nil, options = {}) query, options = nil, query if query.is_a?(Hash) @query, @options = query, options populate if options[:populate] end
# File lib/thinking_sphinx/search.rb, line 31 def context @context ||= ThinkingSphinx::Search::Context.new self, ThinkingSphinx::Configuration.instance end
# File lib/thinking_sphinx/search.rb, line 36 def current_page options[:page] = 1 if options[:page].blank? options[:page].to_i end
# File lib/thinking_sphinx/search.rb, line 41 def masks @masks ||= @options[:masks] || DEFAULT_MASKS.clone end
# File lib/thinking_sphinx/search.rb, line 45 def meta populate context[:meta] end
# File lib/thinking_sphinx/search.rb, line 50 def offset @options[:offset] || ((current_page - 1) * per_page) end
# File lib/thinking_sphinx/search.rb, line 56 def per_page(value = nil) @options[:limit] = value unless value.nil? @options[:limit] ||= (@options[:per_page] || 20) @options[:limit].to_i end
# File lib/thinking_sphinx/search.rb, line 64 def populate return self if @populated middleware.call [context] @populated = true self end
# File lib/thinking_sphinx/search.rb, line 73 def populated! @populated = true end
# File lib/thinking_sphinx/search.rb, line 77 def query_time meta['time'].to_f end
# File lib/thinking_sphinx/search.rb, line 81 def raw populate context[:raw] end
# File lib/thinking_sphinx/search.rb, line 86 def respond_to?(method, include_private = false) super || context[:results].respond_to?(method, include_private) end
# File lib/thinking_sphinx/search.rb, line 90 def to_a populate context[:results].collect { |result| result.respond_to?(:unglazed) ? result.unglazed : result } end
# File lib/thinking_sphinx/search.rb, line 99 def default_middleware options[:ids_only] ? ThinkingSphinx::Middlewares::IDS_ONLY : ThinkingSphinx::Middlewares::DEFAULT end
# File lib/thinking_sphinx/search.rb, line 104 def mask_stack @mask_stack ||= masks.collect { |klass| klass.new self } end
# File lib/thinking_sphinx/search.rb, line 108 def method_missing(method, *args, &block) mask_stack.each do |mask| return mask.send(method, *args, &block) if mask.can_handle?(method) end populate if !SAFE_METHODS.include?(method.to_s) context[:results].send(method, *args, &block) end
# File lib/thinking_sphinx/search.rb, line 118 def middleware @options[:middleware] || default_middleware end