Skip to content

Instantly share code, notes, and snippets.

@joemsak
Created August 14, 2012 18:37
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joemsak/3351556 to your computer and use it in GitHub Desktop.
Save joemsak/3351556 to your computer and use it in GitHub Desktop.
Tire, Bonsai Elastic Search
include Tire::Model::Search
index_name BONSAI_INDEX_NAME
mapping do
indexes :id, :index => :not_analyzed
indexes :title, :analyzer => 'snowball', :boost => 100
indexes :body, :analyzer => 'snowball'
end
after_save do
update_index unless drafted? || hidden?
end
after_destroy do
update_index
end
include Tire::Model::Search
include Tire::Model::Callbacks
index_name BONSAI_INDEX_NAME
mapping do
indexes :id, :index => :not_analyzed
indexes :title, :analyzer => 'snowball', :boost => 100
indexes :description, :analyzer => 'snowball'
indexes :categories, :analyzer => 'snowball', :as => "categories.collect(&:name)"
end
if ENV['BONSAI_INDEX_URL']
Tire.configure do
url "http://index.bonsai.io"
logger $stdout
end
BONSAI_INDEX_NAME = ENV['BONSAI_INDEX_URL'][/[^\/]+$/]
else
app_name = Rails.application.class.parent_name.underscore.dasherize
app_env = Rails.env
BONSAI_INDEX_NAME = "#{app_name}-#{app_env}"
end
gem "tire", "~> 0.4.2"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment