FEATURE: in:tracking and in:watching search filters
This commit is contained in:
parent
8afd7a7f21
commit
e6cc4cba8b
3 changed files with 20 additions and 0 deletions
|
@ -2134,5 +2134,7 @@ en:
|
||||||
`user:foo` Only show posts by the user `foo`
|
`user:foo` Only show posts by the user `foo`
|
||||||
`in:likes` Only show posts you liked
|
`in:likes` Only show posts you liked
|
||||||
`in:posted` Only show posts you created
|
`in:posted` Only show posts you created
|
||||||
|
`in:watching` Only show watched topics
|
||||||
|
`in:tracking` Only show tracking topics
|
||||||
|
|
||||||
Example: `bears category:test status:open order:latest` will search for topics in the category bears that are not closed or archived ordered by last post date.
|
Example: `bears category:test status:open order:latest` will search for topics in the category bears that are not closed or archived ordered by last post date.
|
||||||
|
|
|
@ -171,6 +171,12 @@ class Search
|
||||||
elsif word == 'in:posted'
|
elsif word == 'in:posted'
|
||||||
@posted_only = true
|
@posted_only = true
|
||||||
nil
|
nil
|
||||||
|
elsif word == 'in:watching'
|
||||||
|
@notification_level = TopicUser.notification_levels[:watching]
|
||||||
|
nil
|
||||||
|
elsif word == 'in:tracking'
|
||||||
|
@notification_level = TopicUser.notification_levels[:tracking]
|
||||||
|
nil
|
||||||
else
|
else
|
||||||
word
|
word
|
||||||
end
|
end
|
||||||
|
@ -306,6 +312,14 @@ class Search
|
||||||
posts = posts.where("posts.user_id = #{@guardian.user.id}")
|
posts = posts.where("posts.user_id = #{@guardian.user.id}")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if @notification_level
|
||||||
|
posts = posts.where("posts.topic_id IN (
|
||||||
|
SELECT tu.topic_id FROM topic_users tu
|
||||||
|
WHERE tu.user_id = #{@guardian.user.id} AND
|
||||||
|
tu.notification_level >= #{@notification_level}
|
||||||
|
)")
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# If we have a search context, prioritize those posts first
|
# If we have a search context, prioritize those posts first
|
||||||
|
|
|
@ -328,6 +328,10 @@ describe Search do
|
||||||
|
|
||||||
Search.execute('test in:posted', guardian: Guardian.new(topic.user)).posts.length.should == 1
|
Search.execute('test in:posted', guardian: Guardian.new(topic.user)).posts.length.should == 1
|
||||||
|
|
||||||
|
TopicUser.change(topic.user.id, topic.id, notification_level: TopicUser.notification_levels[:tracking])
|
||||||
|
Search.execute('test in:watching', guardian: Guardian.new(topic.user)).posts.length.should == 0
|
||||||
|
Search.execute('test in:tracking', guardian: Guardian.new(topic.user)).posts.length.should == 1
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'can find by latest' do
|
it 'can find by latest' do
|
||||||
|
|
Reference in a new issue