Created
September 20, 2009 22:08
-
-
Save peteroome/189956 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| # Thinking Sphinx Rake Tasks | |
| rake thinking_sphinx:start | |
| rake thinking_sphinx:stop | |
| rake thinking_sphinx:restart | |
| rake thinking_sphinx:index | |
| # Models | |
| class Article < ActiveRecord::Base | |
| define_index do | |
| indexes headline | |
| indexes body | |
| indexes comments.body, :as => :comment_body | |
| indexes created_at, :sortable => true | |
| indexes published | |
| has author_id | |
| where "published IS TRUE" | |
| end | |
| end | |
| class Review < ActiveRecord::Base | |
| define_index do | |
| indexes title | |
| indexes artist_author | |
| indexes release_date | |
| indexes headline | |
| indexes body | |
| indexes comments.body, :as => :comment_body | |
| indexes created_at, :sortable => true | |
| indexes published | |
| where "published IS TRUE" | |
| end | |
| end | |
| # Routes | |
| map.search "/search", :controller => "search", :action => 'index' | |
| # Search Controller | |
| class SearchController < ApplicationController | |
| def index | |
| @items = ThinkingSphinx.search params[:search], :per_page => 18 | |
| end | |
| end | |
| # Search Form | |
| <% form_tag search_path, :method => 'get' do %> | |
| <div class="search_box"> | |
| <%= text_field_tag :search, params[:search] %> | |
| </div> | |
| <div class="search_button"> | |
| <%= image_submit_tag "/images/search_icon.gif", :alt => "Search", :id => "button_search" %> | |
| </div> | |
| <% end %> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment