Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Search endpoint most recently people #3126

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions app/api/srch/search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,18 @@ class Search < Grape::API
Search.execute(:profiles, params)
end

# Request URL should be /api/srch/recentprofiles?srchString=QRY[&seq=KEYCOUNT&showCount=NUM_ROWS&pageNum=PAGE_NUM]
desc 'Perform a search of profiles', hidden: false,
is_array: false,
nickname: 'srchGetRecentProfiles'

params do
use :common
end
get :recentprofiles do
Search.execute(:recentprofiles, params)
end

# Request URL should be /api/srch/notes?srchString=QRY[&seq=KEYCOUNT&showCount=NUM_ROWS&pageNum=PAGE_NUM]
# Basic implementation from classic plots2 SearchController
desc 'Perform a search of research notes', hidden: false,
Expand Down
2 changes: 2 additions & 0 deletions app/services/execute_search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ def execute(type, search_criteria)
sresult = sservice.textSearch_all(search_criteria.query)
when :profiles
sresult = sservice.textSearch_profiles(search_criteria.query)
when :recentprofiles
sresult = sservice.textSearch_recentProfiles(search_criteria.query)
when :notes
sresult = sservice.textSearch_notes(search_criteria.query)
when :questions
Expand Down
31 changes: 30 additions & 1 deletion app/services/search_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,30 @@ def textSearch_profiles(srchString)
sresult
end

# Search for more recently updated profiles for matching text
def textSearch_recentProfiles(srchString)
sresult = DocList.new

nodes = Node.all.order("changed DESC").limit(100).distinct
users = []
nodes.each do |node|
next unless node.author.status != 0
if node.author.name.downcase.include? srchString.downcase
users << node.author.user
end
end

users = users.uniq

# User profiles
users.each do |match|
doc = DocResult.fromSearch(0, 'user', '/profile/' + match.name, match.name, '', 0)
sresult.addDoc(doc)
end

sresult
end

# Search notes for matching strings
def textSearch_notes(srchString)
sresult = DocList.new
Expand Down Expand Up @@ -242,7 +266,7 @@ def tagNearbyNodes(srchString, tagName)
def recentPeople(srchString, tagName = nil)
sresult = DocList.new

nodes = Node.all.order("changed DESC").limit(srchString).distinct
nodes = Node.all.order("changed DESC").limit(100).distinct
users = []
nodes.each do |node|
if node.author.status != 0
Expand All @@ -254,6 +278,7 @@ def recentPeople(srchString, tagName = nil)
end
end
users = users.uniq
count = 0
users.each do |user|
next unless user.has_power_tag("lat") && user.has_power_tag("lon")
blurred = false
Expand All @@ -262,6 +287,10 @@ def recentPeople(srchString, tagName = nil)
end
doc = DocResult.fromLocationSearch(user.id, 'people_coordinates', user.path, user.username, 0, 0, user.lat, user.lon, blurred)
sresult.addDoc(doc)
count += 1
if count == srchString.to_i
break
end
end

sresult
Expand Down
24 changes: 24 additions & 0 deletions test/functional/search_api_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,30 @@ def app

end

test 'search recent profiles functionality' do
get '/api/srch/recentprofiles?srchString=Jeff'
assert last_response.ok?

# Expected search pattern
pattern = {
srchParams: {
srchString: 'Jeff',
seq: nil,
}.ignore_extra_keys!
}.ignore_extra_keys!

matcher = JsonExpressions::Matcher.new(pattern)

json = JSON.parse(last_response.body)

assert_equal "/profile/jeff", json['items'][0]['docUrl']
assert_equal "jeff", json['items'][0]['docTitle']
assert_equal "user", json['items'][0]['docType']

assert matcher =~ json

end

test 'search notes functionality' do
get '/api/srch/notes?srchString=Blog'
assert last_response.ok?
Expand Down