Skip to content
Extraits de code Groupes Projets
Valider f0cb2159 rédigé par Raphael Sofaer's avatar Raphael Sofaer
Parcourir les fichiers

Make contacts appear at the beginning of search results in postgreSQL

parent ab398555
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -71,11 +71,24 @@ class Person < ActiveRecord::Base
sql, tokens = self.search_query_string(query)
Person.searchable.where(sql, *tokens).joins(
"LEFT OUTER JOIN `contacts` ON `contacts`.user_id = #{user.id} AND `contacts`.person_id = `people`.id"
"LEFT OUTER JOIN contacts ON contacts.user_id = #{user.id} AND contacts.person_id = people.id"
).includes(:profile
).order("contacts.user_id DESC", "profiles.last_name ASC", "profiles.first_name ASC")
).order(search_order)
end
# @return [Array<String>] postgreSQL and mysql deal with null values in orders differently, it seems.
def self.search_order
@search_order ||= Proc.new {
order = if defined?(ActiveRecord::ConnectionAdapters::PostgreSQLAdapter) && ActiveRecord::Base.connection.is_a?(ActiveRecord::ConnectionAdapters::PostgreSQLAdapter)
"ASC"
else
"DESC"
end
["contacts.user_id #{order}", "profiles.last_name ASC", "profiles.first_name ASC"]
}.call
end
def self.public_search(query, opts={})
return [] if query.to_s.blank? || query.to_s.length < 3
......
......@@ -282,29 +282,6 @@ describe Person do
people = Person.search("AAA", @user)
people.map{|p| p.name}.should == [@casey_grippi, @yevgeniy_dodis, @robert_grimm, @eugene_weinstein].map{|p|p.name}
end
it "puts the searching user's incoming requests first" do
requestor = Factory(:user_with_aspect)
profile = requestor.person.profile
profile.first_name = "AAA"
profile.last_name = "Something"
profile.save
@robert_grimm.profile.first_name = "AAA"
@robert_grimm.profile.save
@eugene_weinstein.profile.first_name = "AAA"
@eugene_weinstein.profile.save
@yevgeniy_dodis.profile.first_name = "AAA"
@yevgeniy_dodis.profile.save
@casey_grippi.profile.first_name = "AAA"
@casey_grippi.profile.save
requestor.share_with(@user.person, requestor.aspects.first)
people = Person.search("AAA", @user)
people.map{|p| p.name}.should == [requestor.person, @yevgeniy_dodis, @robert_grimm, @casey_grippi, @eugene_weinstein].map{|p|p.name}
end
end
context 'people finders for webfinger' do
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter