Skip to content

Commit

Permalink
using find_users
Browse files Browse the repository at this point in the history
  • Loading branch information
milaaraujo authored and Stefanni committed Aug 8, 2018
1 parent 0f62acd commit d72f02a
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class User < ActiveRecord::Base
after_destroy :destroy_drupal_user

def self.search(query)
User.where('MATCH(username, bio) AGAINST(?)', query)
User.where('MATCH(username, bio) AGAINST (?)', query)
end

def new_contributor
Expand Down
10 changes: 5 additions & 5 deletions app/services/search_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,19 @@ def textSearch_all(search_criteria)
# If no sort_by value present, then it returns a list of profiles ordered by id DESC
# a recent activity may be a node creation or a node revision
def textSearch_profiles(search_criteria)
user_scope = User.where('username LIKE ? AND rusers.status = 1', '%' + search_criteria.query + '%')
user_scope = SrchScope.find_users(search_criteria.query, limit = 10)
.reorder('')

user_scope =
if search_criteria.sort_by == "recent"
user_scope.joins(:revisions)
.order("node_revisions.timestamp #{search_criteria.order_direction}")
.distinct # do we need unique/distinct on user id ?

.distinct
else
user_scope.order(id: :desc) # order by what when order_by is not present? id? username?
user_scope.order(id: :desc)
end

users = user_scope.limit(10) # verify limit?
users = user_scope.limit(10)

sresult = DocList.new
users.each do |match|
Expand Down
8 changes: 4 additions & 4 deletions app/services/srch_scope.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ class SrchScope
def self.find_users(input, limit)
if ActiveRecord::Base.connection.adapter_name == 'Mysql2'
User.search(input)
.order('id DESC') # do we need this line?
.where('rusers.status = ?', 1)
.order('id DESC')
.where(status: 1)
.limit(limit)
else
User.order('id DESC')
.where('username LIKE ? AND rusers.status = 1', '%' + input + '%')
User.where('username LIKE ? AND rusers.status = 1', '%' + input + '%')
.order('id DESC')
.limit(limit)
end
end
Expand Down
4 changes: 2 additions & 2 deletions test/fixtures/nodes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ post_test1:

post_test2:
nid: 24
uid: 16
uid: 17
title: "Post Test 2"
path: "/notes/user2/<%= DateTime.new(2018,8,8).strftime("%m-%d-%Y") %>/post-test2"
created: <%= DateTime.new(2018,8,8).to_i %>
Expand All @@ -285,7 +285,7 @@ post_test2:

post_test3:
nid: 25
uid: 17
uid: 16
title: "Post Test 3"
path: "/notes/user3/<%= DateTime.new(2018,8,15).strftime("%m-%d-%Y") %>/post-test3"
created: <%= DateTime.new(2018,8,15).to_i %>
Expand Down
4 changes: 2 additions & 2 deletions test/fixtures/revisions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -287,14 +287,14 @@ post_test1:

post_test2:
nid: 24
uid: 16
uid: 17
title: Post test review 2
body: Post test review 2
timestamp: <%= DateTime.new(2018,8,8).to_i %>

post_test3:
nid: 25
uid: 17
uid: 16
title: Post test review 2
body: Post test review 2
timestamp: <%= DateTime.new(2018,8,15).to_i %>
8 changes: 4 additions & 4 deletions test/functional/search_api_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ def app

json = JSON.parse(last_response.body)

assert_equal "steff3", json['items'][0]['docTitle']
assert_equal "steff2", json['items'][1]['docTitle']
assert_equal "steff2", json['items'][0]['docTitle']
assert_equal "steff3", json['items'][1]['docTitle']
assert_equal "steff1", json['items'][2]['docTitle']

assert matcher =~ json
Expand All @@ -142,8 +142,8 @@ def app
json = JSON.parse(last_response.body)

assert_equal "/profile/steff1", json['items'][0]['docUrl']
assert_equal "/profile/steff2", json['items'][1]['docUrl']
assert_equal "/profile/steff3", json['items'][2]['docUrl']
assert_equal "/profile/steff3", json['items'][1]['docUrl']
assert_equal "/profile/steff2", json['items'][2]['docUrl']

assert matcher =~ json
end
Expand Down

0 comments on commit d72f02a

Please sign in to comment.