class ThinkingSphinx::Search

Constants

CORE_METHODS
DEFAULT_MASKS
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 24
def initialize(query = nil, options = {})
  query, options   = nil, query if query.is_a?(Hash)
  @query, @options = query, options

  populate if options[:populate]
end

Public Instance Methods

context() click to toggle source
# File lib/thinking_sphinx/search.rb, line 31
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 36
def current_page
  options[:page] = 1 if options[:page].blank?
  options[:page].to_i
end
limit_value(value = nil)
Alias for: per_page
masks() click to toggle source
# File lib/thinking_sphinx/search.rb, line 41
def masks
  @masks ||= @options[:masks] || DEFAULT_MASKS.clone
end
meta() click to toggle source
# File lib/thinking_sphinx/search.rb, line 45
def meta
  populate
  context[:meta]
end
offset() click to toggle source
# File lib/thinking_sphinx/search.rb, line 50
def offset
  @options[:offset] || ((current_page - 1) * per_page)
end
Also aliased as: offset_value
offset_value()
Alias for: offset
per_page(value = nil) click to toggle source
# 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
Also aliased as: limit_value
populate() click to toggle source
# File lib/thinking_sphinx/search.rb, line 64
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 73
def populated!
  @populated = true
end
populated?() click to toggle source
# File lib/thinking_sphinx/search.rb, line 77
def populated?
  @populated
end
query_time() click to toggle source
# File lib/thinking_sphinx/search.rb, line 81
def query_time
  meta['time'].to_f
end
raw() click to toggle source
# File lib/thinking_sphinx/search.rb, line 85
def raw
  populate
  context[:raw]
end
to_a() click to toggle source
# File lib/thinking_sphinx/search.rb, line 90
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 99
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 104
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 108
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 112
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 128
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 122
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 132
def results_respond_to?(method, include_private = true)
  context[:results].respond_to?(method, include_private)
end