Skip to content

Instantly share code, notes, and snippets.

@pat
Created April 30, 2011 01:50
Show Gist options
  • Save pat/949331 to your computer and use it in GitHub Desktop.
Save pat/949331 to your computer and use it in GitHub Desktop.
Thinking Sphinx with Sinatra
# 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
require 'app'
require 'thinking_sphinx/tasks'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment