---
title: "#120 Thinking Sphinx"
author: "CaiDeHen"
date: "2008-12-12T16:59:56Z"
tags: []
slug: "120-thinking-sphinx"
draft: false
lastmod: "2008-12-12T16:59:56Z"
id: 292473
url: "https://caidehen.iteye.com/blog/292473"
---

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

```java
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
```