Created
April 30, 2011 01:50
-
-
Save pat/949331 to your computer and use it in GitHub Desktop.
Thinking Sphinx with Sinatra
This file contains 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
# Super simple sample app. You'll need to create config and log directories to make everything happy, but beyond that, should be smooth sailing with the latest from GitHub (not in a gem release just yet). | |
# mkdir -p config | |
# mkdir -p log | |
require 'rubygems' | |
require 'sinatra' | |
require 'mysql' | |
require 'active_record' | |
require 'thinking-sphinx' | |
ActiveRecord::Base.establish_connection( | |
'adapter' => 'mysql', | |
'database' => 'thinking_sphinx', | |
'username' => 'root' | |
) | |
ActiveSupport.on_load :active_record do | |
include ThinkingSphinx::ActiveRecord | |
end | |
class Alpha < ActiveRecord::Base | |
define_index do | |
indexes :name | |
end | |
end | |
get '/' do | |
'<ul>' + | |
Alpha.search.collect { |a| "<li>#{a.name}</li>" }.join('') + | |
'</ul>' | |
end |
This file contains 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
require 'app' | |
require 'thinking_sphinx/tasks' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment