Created
November 13, 2013 21:08
-
-
Save toddsampson/7456440 to your computer and use it in GitHub Desktop.
Default scope with Sunspot blog post: 2010/01/15/default-scope-with-sunspot/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Item | |
# simple default scope to add an order_by to all queries | |
def self.default_search_scope(&additional) | |
search = Sunspot.new_search(Item) | |
search.build(&additional) | |
search.build do | |
order_by :created_at, :desc | |
end | |
search.execute | |
search.results | |
end | |
# pardon the contrived example | |
def self.with_keywords(user, query) | |
default_search_scope do | |
keywords query | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment