FEATURE: search for all posts by a group
This commit is contained in:
parent
17d999ab12
commit
6496895096
|
@ -233,6 +233,15 @@ class Search
|
|||
end
|
||||
end
|
||||
|
||||
advanced_filter(/group:(.+)/) do |posts,match|
|
||||
group_id = Group.where('name ilike ? OR (id = ? AND id > 0)', match, match.to_i).pluck(:id).first
|
||||
if group_id
|
||||
posts.where("posts.user_id IN (select gu.user_id from group_users gu where gu.group_id = ?)", group_id)
|
||||
else
|
||||
posts.where("1 = 0")
|
||||
end
|
||||
end
|
||||
|
||||
advanced_filter(/user:(.+)/) do |posts,match|
|
||||
user_id = User.where('username_lower = ? OR id = ?', match.downcase, match.to_i).pluck(:id).first
|
||||
if user_id
|
||||
|
|
|
@ -391,6 +391,17 @@ describe Search do
|
|||
expect(Search.execute("user:#{_post.user.username}").posts.length).to eq(1)
|
||||
end
|
||||
|
||||
it 'supports group' do
|
||||
topic = Fabricate(:topic, created_at: 3.months.ago)
|
||||
post = Fabricate(:post, raw: 'hi this is a test 123 123', topic: topic)
|
||||
|
||||
group = Group.create!(name: "Like_a_Boss")
|
||||
GroupUser.create!(user_id: post.user_id, group_id: group.id)
|
||||
|
||||
expect(Search.execute('group:like_a_boss').posts.length).to eq(1)
|
||||
expect(Search.execute('group:"like a brick"').posts.length).to eq(0)
|
||||
end
|
||||
|
||||
it 'supports with_badge' do
|
||||
|
||||
topic = Fabricate(:topic, created_at: 3.months.ago)
|
||||
|
|
Loading…
Reference in New Issue