Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@bkeepers
Created February 13, 2009 00:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bkeepers/62972 to your computer and use it in GitHub Desktop.
Save bkeepers/62972 to your computer and use it in GitHub Desktop.
# Thoughts on a backend-agnostic search plugin
Scour.define Model do
backend :ferret # or :sphinx / :solr
index title, :sortable => true, :boost => 1.0
index content, author_id, created_at, updated_at
index author.name, :as => :author, :sortable => true
index first_name, last_name, :as => [:name, :fullname]
index tags.name, :as => :tags
index minor { author.age < 18 }
where { active? }
boost votes.count
age 3.days
end
Scour.define 'multi' do
backend :ferret
with Foo do
index name
end
with Bar do
index thing
end
end
# AR style
Model.search(:conditions => {:title => 'foo', :created_at => 1.week.ago..Time.now})
# Freeform
Model.search('foo', :order => :title)
# specific index
Scour['multi'].search('…')
# or
Scour.search '…', :in => 'multi'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment