Skip to content

Instantly share code, notes, and snippets.

@bernardo-cs
Created March 22, 2015 18:52
Show Gist options
  • Save bernardo-cs/a8ab71d931ff68b40337 to your computer and use it in GitHub Desktop.
Save bernardo-cs/a8ab71d931ff68b40337 to your computer and use it in GitHub Desktop.
meta search
class TweetsController < ApplicationController
def search
@result = sort( Tweet.search_text( search_query ) )
end
private
def search_query
params[:q]
end
def sort result
sort_options[sort_type].call( result )
end
def sort_type
params[:sort]
end
def sort_options
{
"favourites" => ->( result ){ result.order( favourites: :desc ) },
"retweets" => ->( result ){ result.order( retweets: :desc ) }
}.tap{ |hsh|
hsh.default = ->( result ){ result.order( retweets: :desc, favourites: :desc ) }
}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment