Created
January 17, 2009 12:34
-
-
Save pat/48328 to your computer and use it in GitHub Desktop.
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
# Current Facets Support: | |
# | |
# Single-model searches only | |
# | |
class Person < ActiveRecord::Base | |
define_index do | |
indexes state, :facet => true | |
has year, :facet => true | |
facet city | |
end | |
end | |
# Use same arguments as #search method. | |
Person.facets "blah" #=> | |
# { | |
# :state => { | |
# "Victoria" => 10, | |
# "New South Wales" => 5, | |
# "Queensland" => 4, | |
# "Tasmania" => 3, | |
# "Northern Territory" => 3 | |
# }, | |
# :year => { | |
# 2006 => 5, | |
# 2007 => 8, | |
# 2008 => 10, | |
# 2009 => 2 | |
# }, | |
# :city => { | |
# "Melbourne" => 8, | |
# "Bendigo" => 2, | |
# "Sydney" => 4, | |
# "Gosford" => 1, | |
# "Brisbane" => 4, | |
# "Launceston" => 1, | |
# "Hobart" => 2, | |
# "Darwin" => 2, | |
# "Alice Springs" => 1 | |
# } | |
# } | |
@facets = Person.facets("blah") | |
@facets.for(:state => "Victoria") #=> | |
# [ | |
# <#Person ..>, | |
# <#Person ..>, | |
# <#Person ..>, | |
# <#Person ..>, | |
# ... | |
# ] | |
# You can drill down by multiple facets at once, too: | |
@facets.for(:state => "Victoria", :city => "Melbourne") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment