Skip to content

Instantly share code, notes, and snippets.

@Prav92
Created July 19, 2017 14:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Prav92/775942c2617f94c33130191514993231 to your computer and use it in GitHub Desktop.
Save Prav92/775942c2617f94c33130191514993231 to your computer and use it in GitHub Desktop.
def self.sort_by_top_search_algorithm current_user, orig_lat, orig_lon
p "sort_by_top_search_algorithm =----------------------------------=--=-==-=-=opklkklkl"
healthcare_provider_list =[]
if orig_lat != 0.0 && orig_lon != 0.0
nearby = self.having("distance <= 25")
others = self.having("distance > 25 && distance <= 100")
else
nearby = []
others = self.having("distance is ?",nil)
end
if !current_user.nil?
# Sorting by reviews, over_all_rating, distance and full_name
healthcare_provider_list += nearby.sort_by{|a,b| [-a.get_recommended_by_in_array(current_user.id, a.type_id, false).size, -a.get_overall_rating(a.type_id), a["distance"], a["full_name"]]} if !nearby.blank?
healthcare_provider_list += others.sort_by{|a,b| [-a.get_recommended_by_in_array(current_user.id, a.type_id, false).size, -a.get_overall_rating(a.type_id), a["distance"], a["full_name"]]}
else
# Sorting by reviews, over_all_rating, distance and full_name
healthcare_provider_list += nearby.sort_by{|a,b| [-a.get_overall_rating(a.type_id), a["distance"], a["full_name"]]} if !nearby.blank?
healthcare_provider_list += others.sort_by{|a,b| [-a.get_overall_rating(a.type_id), a["distance"], a["full_name"]]}
end
return healthcare_provider_list.uniq
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment