Skip to content

Instantly share code, notes, and snippets.

@peteroome
Created September 20, 2009 22:08
Show Gist options
  • Select an option

  • Save peteroome/189956 to your computer and use it in GitHub Desktop.

Select an option

Save peteroome/189956 to your computer and use it in GitHub Desktop.
# 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