Skip to content

Commit

Permalink
Refactoring getRecentProfiles method
Browse files Browse the repository at this point in the history
  • Loading branch information
milaaraujo authored and Stefanni committed Jul 26, 2018
1 parent e54f2a9 commit c01cae5
Showing 1 changed file with 23 additions and 12 deletions.
35 changes: 23 additions & 12 deletions app/services/search_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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|
Expand All @@ -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

0 comments on commit c01cae5

Please sign in to comment.