Skip to content

Instantly share code, notes, and snippets.

View benzheren's full-sized avatar

Zheren (Ben) Hu benzheren

View GitHub Profile
#!/usr/bin/env /usr/local/rvm/rubies/ruby-1.9.3-p194/bin/ruby
CODES = {
'400' => 'Bad Request',
'401' => 'Unauthorized',
'403' => 'Forbidden',
'404' => 'Not Found',
'405' => 'Method Not Allowed',
'406' => 'Not Acceptable',
'408' => 'Request Timeout',
@benzheren
benzheren / search_controller.rb
Created November 10, 2011 12:37
Tire Search Code using DSL
@s = Tire.search index_path,
:from => 0,
:size => 100,
:query => {"text" => {"_all" => query}},
:highlight => {"fields" => {"text" => {}},
"pre_tags" => ["<strong class=\"highlight\">"],
"post_tags" => ["</strong>"]}
@benzheren
benzheren / search_controller.rb
Created August 25, 2011 02:58
A Rails Controller uses Tire to interface with ElasticSearch.
class SearchController < ApplicationController
def ajax
q = request.GET[:q]
@s = Tire.search(sha1 current_user.email) do
query do
string q
end
highlight :text, :options => { :tag => '<strong class="highlight">' }
end
puts @s.to_curl