class ThinkingSphinx::Search
Constants
- CORE_METHODS
- DEFAULT_MASKS
- KNOWN_OPTIONS
- SAFE_METHODS
Attributes
options[R]
query[RW]
Public Class Methods
new(query = nil, options = {})
click to toggle source
# File lib/thinking_sphinx/search.rb, line 39 def initialize(query = nil, options = {}) query, options = nil, query if query.is_a?(Hash) @query, @options = query, options populate if options[:populate] end
valid_options()
click to toggle source
# File lib/thinking_sphinx/search.rb, line 33 def self.valid_options @valid_options end
Public Instance Methods
context()
click to toggle source
# File lib/thinking_sphinx/search.rb, line 46 def context @context ||= ThinkingSphinx::Search::Context.new self, ThinkingSphinx::Configuration.instance end
current_page()
click to toggle source
# File lib/thinking_sphinx/search.rb, line 51 def current_page options[:page] = 1 if options[:page].blank? options[:page].to_i end
marshal_dump()
click to toggle source
# File lib/thinking_sphinx/search.rb, line 56 def marshal_dump populate [@populated, @query, @options, @context] end
marshal_load(array)
click to toggle source
# File lib/thinking_sphinx/search.rb, line 62 def marshal_load(array) @populated, @query, @options, @context = array end
masks()
click to toggle source
# File lib/thinking_sphinx/search.rb, line 66 def masks @masks ||= @options[:masks] || DEFAULT_MASKS.clone end
meta()
click to toggle source
# File lib/thinking_sphinx/search.rb, line 70 def meta populate context[:meta] end
offset()
click to toggle source
# File lib/thinking_sphinx/search.rb, line 75 def offset @options[:offset] || ((current_page - 1) * per_page) end
Also aliased as: offset_value
per_page(value = nil)
click to toggle source
# File lib/thinking_sphinx/search.rb, line 81 def per_page(value = nil) @options[:limit] = value unless value.nil? @options[:limit] ||= (@options[:per_page] || 20) @options[:limit].to_i end
Also aliased as: limit_value
populate()
click to toggle source
# File lib/thinking_sphinx/search.rb, line 89 def populate return self if @populated middleware.call [context] @populated = true self end
populated!()
click to toggle source
# File lib/thinking_sphinx/search.rb, line 98 def populated! @populated = true end
populated?()
click to toggle source
# File lib/thinking_sphinx/search.rb, line 102 def populated? @populated end
query_time()
click to toggle source
# File lib/thinking_sphinx/search.rb, line 106 def query_time meta['time'].to_f end
raw()
click to toggle source
# File lib/thinking_sphinx/search.rb, line 110 def raw populate context[:raw] end
to_a()
click to toggle source
# File lib/thinking_sphinx/search.rb, line 115 def to_a populate context[:results].collect { |result| result.respond_to?(:unglazed) ? result.unglazed : result } end
Private Instance Methods
default_middleware()
click to toggle source
# File lib/thinking_sphinx/search.rb, line 124 def default_middleware options[:ids_only] ? ThinkingSphinx::Middlewares::IDS_ONLY : ThinkingSphinx::Middlewares::DEFAULT end
mask_stack()
click to toggle source
# File lib/thinking_sphinx/search.rb, line 129 def mask_stack @mask_stack ||= masks.collect { |klass| klass.new self } end
masks_respond_to?(method)
click to toggle source
# File lib/thinking_sphinx/search.rb, line 133 def masks_respond_to?(method) mask_stack.any? { |mask| mask.can_handle? method } end
method_missing(method, *args, &block)
click to toggle source
# File lib/thinking_sphinx/search.rb, line 137 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
middleware()
click to toggle source
# File lib/thinking_sphinx/search.rb, line 153 def middleware @options[:middleware] || default_middleware end
respond_to_missing?(method, include_private = false)
click to toggle source
Calls superclass method
# File lib/thinking_sphinx/search.rb, line 147 def respond_to_missing?(method, include_private = false) super || masks_respond_to?(method) || results_respond_to?(method, include_private) end
results_respond_to?(method, include_private = true)
click to toggle source
# File lib/thinking_sphinx/search.rb, line 157 def results_respond_to?(method, include_private = true) context[:results].respond_to?(method, include_private) end