Created
March 28, 2012 20:55
-
-
Save mrdanadams/2230436 to your computer and use it in GitHub Desktop.
Revisions
-
mrdanadams created this gist
Mar 28, 2012 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,17 @@ ids = current_user.facebook_friends if current_user @search = Profile.solr_search do keywords params[:q] do boost_fields name: 10.0, user: 4.0 end unless ids.blank? adjust_solr_params do |params| # See "bq (boost query)" in http://wiki.apache.org/solr/DisMaxQParserPlugin params[:bq] = "facebook_id_s:(#{ids.join(' OR ')})^10" end end paginate page: params[:page], per_page: page_size end @results = @search.results 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,9 @@ searchable do # some normal fields to search text :name, :description # index the ids as an array of strings (not text) as we want exact match, no stemming, etc string :facebook_id do user.facebook_id end end 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,22 @@ # Returns a user associated with a facebook account. def self.find_for_facebook_oauth(access_token, signed_in_resource=nil) data = access_token.extra.raw_info if user = User.where(:email => data.email).first user else # Create a user with a stub password. user = User.new email: data.email, first_name: data.first_name, last_name: data.last_name, password: Devise.friendly_token[0,20] facebook_id = data.id token = access_token.credentials.token user.facebook_info = { 'id' => facebook_id, 'token' => token } # in the future we could save the user and get the friends in a background worker if it's too slow fb_user = FbGraph::User.fetch facebook_id, access_token: token user.facebook_friends = fb_user.friends.map &:identifier user.save! user.confirm! user end end