mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-23 15:48:43 -05:00
FEATURE: new search filter - @username
This commit is contained in:
parent
628773258e
commit
00893ef1de
3 changed files with 15 additions and 4 deletions
|
@ -2782,9 +2782,9 @@ en:
|
|||
<h3>Options</h3>
|
||||
<p>
|
||||
<table>
|
||||
<tr><td><code>order:views</code></td><td><code>order:latest</code></td><td><code>order:likes</code><td></td><td colspan=2></td></tr>
|
||||
<tr><td><code>order:views</code></td><td><code>order:latest</code></td><td><code>order:likes</code></td><td><code>@username</code></td><td><code>user:foo</code></td></tr>
|
||||
<tr><td><code>status:open</code></td><td><code>status:closed</code></td><td><code>status:archived</code></td><td><code>status:noreplies</code></td><td><code>status:single_user</code></td></tr>
|
||||
<tr><td><code>#category-slug</code></td><td><code>category:foo</code></td><td><code>user:foo</code></td><td><code>group:foo</code></td><td><code>badge:foo</code></td><td></td></tr>
|
||||
<tr><td><code>#category-slug</code></td><td><code>category:foo</code></td><td><code>group:foo</code></td><td><code>badge:foo</code></td><td></td></tr>
|
||||
<tr><td><code>in:likes</code></td><td><code>in:posted</code></td><td><code>in:watching</code></td><td><code>in:tracking</code></td><td><code>in:private</code></td></tr>
|
||||
<tr><td><code>in:bookmarks</code></td><td><code>in:first</code></td><td><code>in:pinned</code></td><td><code>in:unpinned</code></td><td></td></tr>
|
||||
<tr><td><code>posts_count:num</code></td><td><code>before:days or date</code></td><td><code>after:days or date</code></td> <td colspan=2></td></tr>
|
||||
|
|
|
@ -279,7 +279,7 @@ class Search
|
|||
end
|
||||
end
|
||||
|
||||
advanced_filter(/^\#([a-zA-Z0-9,\-:]+)/) do |posts,match|
|
||||
advanced_filter(/^\#([a-zA-Z0-9\-:]+)/) do |posts,match|
|
||||
slug = match.to_s.split(":")
|
||||
if slug[1]
|
||||
# sub category
|
||||
|
@ -315,6 +315,15 @@ class Search
|
|||
end
|
||||
end
|
||||
|
||||
advanced_filter(/^\@([a-zA-Z0-9_\-.]+)/) do |posts,match|
|
||||
user_id = User.where(staged: false).where(username_lower: match.downcase).pluck(:id).first
|
||||
if user_id
|
||||
posts.where("posts.user_id = #{user_id}")
|
||||
else
|
||||
posts.where("1 = 0")
|
||||
end
|
||||
end
|
||||
|
||||
advanced_filter(/before:(.*)/) do |posts,match|
|
||||
if date = Search.word_to_date(match)
|
||||
posts.where("posts.created_at < ?", date)
|
||||
|
|
|
@ -426,7 +426,7 @@ describe Search do
|
|||
expect(Search.execute('boom in:unpinned', guardian: guardian).posts.length).to eq(1)
|
||||
end
|
||||
|
||||
it 'supports before and after in:first user:' do
|
||||
it 'supports before and after, in:first, user:, @username' do
|
||||
|
||||
time = Time.zone.parse('2001-05-20 2:55')
|
||||
freeze_time(time)
|
||||
|
@ -449,6 +449,8 @@ describe Search do
|
|||
expect(Search.execute('user:nobody').posts.length).to eq(0)
|
||||
expect(Search.execute("user:#{_post.user.username}").posts.length).to eq(1)
|
||||
expect(Search.execute("user:#{_post.user_id}").posts.length).to eq(1)
|
||||
|
||||
expect(Search.execute("@#{_post.user.username}").posts.length).to eq(1)
|
||||
end
|
||||
|
||||
it 'supports group' do
|
||||
|
|
Loading…
Reference in a new issue