Skip to content

Commit

Permalink
Added some documentation on scopes.
Browse files Browse the repository at this point in the history
  • Loading branch information
Joost Hietbrink authored and pat committed Nov 16, 2009
1 parent bb7f89f commit 99f144b
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion lib/thinking_sphinx/active_record/scopes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,36 @@ def self.included(base)
end

module ClassMethods

# Similar to ActiveRecord's default_scope method Thinking Sphinx supports
# a default_sphinx_scope. For example:
#
# default_sphinx_scope {
# { :order => 'created_at DESC' }
# }
#
# The scope is automatically applied when the search method is called.
# The default_scope can also be created using:
#
# sphinx_scope(:default) {
# { :order => 'created_at DESC' }
# }
#
def default_sphinx_scope(&block)
sphinx_scope(:default, &block)
end

# Similar to ActiveRecord's named_scope method Thinking Sphinx supports
# scopes. For example:
#
# sphinx_scope(:latest_first) {
# {:order => 'created_at DESC, @relevance DESC'}
# }
#
# Usage:
#
# @articles = Article.latest_first.search 'pancakes'
#
def sphinx_scope(method, &block)
@sphinx_scopes ||= []
@sphinx_scopes << method
Expand All @@ -25,7 +51,9 @@ def sphinx_scope(method, &block)
end
end
end


# This returns an Array of all defined scopes. The default
# scope shows as :default.
def sphinx_scopes
@sphinx_scopes || []
end
Expand Down

0 comments on commit 99f144b

Please sign in to comment.