diff --git a/app/services/search_service.rb b/app/services/search_service.rb index e06de80eae5..be12bfd7f6a 100644 --- a/app/services/search_service.rb +++ b/app/services/search_service.rb @@ -51,7 +51,7 @@ def textSearch_profiles(srchString, order = nil) users = if order == "recentdesc" - getRecentProfiles(srchString) + filterMatchingUserName(getRecentProfiles, srchString) else SrchScope.find_users(srchString, limit = nil) end @@ -177,7 +177,10 @@ def tagNearbyNodes(srchString, tagName) # X = srchString def recentPeople(srchString, tagName = nil) sresult = DocList.new - users = getRecentProfilesTag(tagName) + + users = getRecentProfiles + if tagName then users = filterUserTag(users, tagName) end + count = 0 users.each do |user| @@ -196,31 +199,39 @@ def recentPeople(srchString, tagName = nil) end # Get users with matching name ordering by most recent activity - def getRecentProfiles(srchString) + def getRecentProfiles sresult = DocList.new nodes = Node.all.order("changed DESC").limit(100).distinct users = [] nodes.each do |node| - next unless (node.author.status != 0) && (node.author.name.downcase.include? srchString.downcase) + next unless node.author.status != 0 users << node.author.user end users = users.uniq end + def filterMatchingUserName(users, srchString) + usersMatchingName = [] + users.each do |user| + next unless user.name.downcase.include? srchString.downcase + usersMatchingName << user + end + + usersMatchingName + end + # If a tagName is provided, # method returns users with the specific tag ordering by most recent activity. # Otherwise, it returns users with most recent activity. - def getRecentProfilesTag(tagName = nil) - nodes = Node.all.order("changed DESC").limit(100).distinct - users = [] - - nodes.each do |node| - next unless node.author.status != 0 && ((tagName && node.author.user.has_tag(tagName)) || tagName.nil?) - users << node.author.user + def filterUserTag(users, tagName) + usersWithTag = [] + users.each do |user| + next unless user.has_tag(tagName) + usersWithTag << user end - users = users.uniq + usersWithTag end end