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 42 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 36 def self.valid_options @valid_options end
Public Instance Methods
context()
click to toggle source
# File lib/thinking_sphinx/search.rb, line 49 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 54 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 59 def marshal_dump populate [@populated, @query, @options, @context] end
marshal_load(array)
click to toggle source
# File lib/thinking_sphinx/search.rb, line 65 def marshal_load(array) @populated, @query, @options, @context = array end
masks()
click to toggle source
# File lib/thinking_sphinx/search.rb, line 69 def masks @masks ||= @options[:masks] || DEFAULT_MASKS.clone end
meta()
click to toggle source
# File lib/thinking_sphinx/search.rb, line 73 def meta populate context[:meta] end
offset()
click to toggle source
# File lib/thinking_sphinx/search.rb, line 78 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 84 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 92 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 101 def populated! @populated = true end
populated?()
click to toggle source
# File lib/thinking_sphinx/search.rb, line 105 def populated? @populated end
query_time()
click to toggle source
# File lib/thinking_sphinx/search.rb, line 109 def query_time meta['time'].to_f end
raw()
click to toggle source
# File lib/thinking_sphinx/search.rb, line 113 def raw populate context[:raw] end
to_a()
click to toggle source
# File lib/thinking_sphinx/search.rb, line 118 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 127 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 132 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 136 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 140 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 156 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 150 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 160 def results_respond_to?(method, include_private = true) context[:results].respond_to?(method, include_private) end