ITeye博客

#120 Thinking Sphinx

CaiDeHen · 2008-12-12 16:59 · Railscasts · Markdown

If you need a full text search engine, Thinking Sphinx is a great solution. See why in this episode.

script/plugin install git://github.com/freelancing-god/thinking-sphinx.git
rake thinking_sphinx:index
rake thinking_sphinx:start

# models/author.rb
define_index do
  indexes content
  indexes :name, :sortable => true
  indexes comments.content, :as => :comment_content
  indexes [author.first_name, author.last_name], :as => :author_name
  
  has author_id, created_at
end

# articles_controller.rb
@articles = Article.search params[:search]
# :include => :author 
# :conditions => { :created_at => 1.week.ago.to_i..Time.now.to_i }
# :order => :name
# :field_weights => { :name => 20, :content => 10, :author_name => 5 }
# :match_mode => :boolean
# :page => 1, :per_page => 20

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。