Created
March 22, 2015 18:52
-
-
Save bernardo-cs/a8ab71d931ff68b40337 to your computer and use it in GitHub Desktop.
meta search
This file contains hidden or 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
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