module ThinkingSphinx::SearchMethods::ClassMethods

Public Instance Methods

count(*args) click to toggle source
# File lib/thinking_sphinx/search_methods.rb, line 404
def count(*args)
  search_context ? super : search_count(*args)
end
facets(*args) click to toggle source

Model.facets *args ThinkingSphinx.facets *args ThinkingSphinx.facets *args, :all_facets => true ThinkingSphinx.facets *args, :class_facet => false

# File lib/thinking_sphinx/search_methods.rb, line 421
def facets(*args)
  ThinkingSphinx::FacetSearch.new *search_options(args)
end
search_context() click to toggle source
# File lib/thinking_sphinx/search_methods.rb, line 10
def search_context
  # Comparing to name string to avoid class inheritance complications
  case self.class.name
  when 'Class'
    self
  else
    nil
  end
end
search_count(*args) click to toggle source
# File lib/thinking_sphinx/search_methods.rb, line 408
def search_count(*args)
  search = ThinkingSphinx::Search.new(
    *search_options(args, :ids_only => true)
  )
  search.first # forces the query
  search.total_entries
end
search_for_id(id, index, options = {}) click to toggle source

Checks if a document with the given id exists within a specific index. Expected parameters:

  • ID of the document

  • Index to check within

  • Options hash (defaults to {})

Example:

ThinkingSphinx.search_for_id(10, "user_core", :class => User)
# File lib/thinking_sphinx/search_methods.rb, line 394
def search_for_id(id, index, options = {})
  ThinkingSphinx::Search.new(
    *search_options([],
      :ids_only => true,
      :index    => index,
      :id_range => id..id
    )
  ).any?
end
search_for_ids(*args) click to toggle source

Searches for results that match the parameters provided. Will only return the ids for the matching objects. See search for syntax examples.

Note that this only searches the Sphinx index, with no ActiveRecord queries. Thus, if your index is not in sync with the database, this method may return ids that no longer exist there.

# File lib/thinking_sphinx/search_methods.rb, line 379
def search_for_ids(*args)
  ThinkingSphinx::Search.new *search_options(args, :ids_only => true)
end