A platform for community discussion. Free, open, simple.
FEATURE: special shortcut for searching for own posts (#11541)
Sam293b243aeb47
diff --git a/lib/search.rb b/lib/search.rbindex 5f3d7339186..0b3b71003a0 100644--- a/lib/search.rb+++ b/lib/search.rb@@ -617,7 +617,14 @@ class Searchendadvanced_filter(/^\@([a-zA-Z0-9_\-.]+)$/i) do |posts, match|- user_id = User.where(staged: false).where(username_lower: match.downcase).pluck_first(:id)+ username = match.downcase++ user_id = User.where(staged: false).where(username_lower: username).pluck_first(:id)++ if !user_id && username == "me"+ user_id = @guardian.user&.id+ end+if user_idposts.where("posts.user_id = #{user_id}")elsediff --git a/spec/components/search_spec.rb b/spec/components/search_spec.rbindex cc646d0fa4a..5c8c19607db 100644--- a/spec/components/search_spec.rb+++ b/spec/components/search_spec.rb@@ -308,7 +308,7 @@ describe Search docontext 'personal_messages filter' doit 'does not allow a normal user to search for personal messages of another user' doexpect do- results = Search.execute(+ Search.execute("mars personal_messages:#{post.user.username}",guardian: Guardian.new(Fabricate(:user)))@@ -397,16 +397,21 @@ describe Search doit 'can filter direct PMs by @username' dopm = create_pm(users: [current, participant])pm_2 = create_pm(users: [participant, current])- _pm_3 = create_pm(users: [participant_2, current])+ pm_3 = create_pm(users: [participant_2, current])["@#{participant.username} in:personal-direct",- "@#{participant.username} iN:pErSoNaL-dIrEcT"+ "@#{participant.username} iN:pErSoNaL-dIrEcT",].each do |query|results = Search.execute(query, guardian: Guardian.new(current))expect(results.posts.size).to eq(2)- expect(results.posts.map(&:topic_id)).to eq([pm_2.id, pm.id])+ expect(results.posts.map(&:topic_id)).to contain_exactly(pm_2.id, pm.id)expect(results.posts.map(&:user_id).uniq).to eq([participant.id])end++ results = Search.execute("@me in:personal-direct", guardian: Guardian.new(current))+ expect(results.posts.size).to eq(3)+ expect(results.posts.map(&:topic_id)).to contain_exactly(pm_3.id, pm_2.id, pm.id)+ expect(results.posts.map(&:user_id).uniq).to eq([current.id])endit "doesn't include PMs that have more than 2 participants" do@@ -584,7 +589,7 @@ describe Search doendit 'aggregates searches in a topic by returning the post with the highest rank' do- post = Fabricate(:post, topic: topic, raw: "this is a play post")+ _post = Fabricate(:post, topic: topic, raw: "this is a play post")post2 = Fabricate(:post, topic: topic, raw: "play play playing played play")post3 = Fabricate(:post, raw: "this is a play post")@@ -1145,9 +1150,6 @@ describe Search dotopic.update_pinned(true)- user = Fabricate(:user)- guardian = Guardian.new(user)-expect(Search.execute('boom in:pinned').posts.length).to eq(1)expect(Search.execute('boom IN:PINNED').posts.length).to eq(1)end@@ -1727,7 +1729,7 @@ describe Search docontext 'in:title' doit 'allows for search in title' dotopic = Fabricate(:topic, title: 'I am testing a title search')- post2 = Fabricate(:post, topic: topic, raw: 'this is the second post', post_number: 2)+ _post2 = Fabricate(:post, topic: topic, raw: 'this is the second post', post_number: 2)post = Fabricate(:post, topic: topic, raw: 'this is the first post', post_number: 1)results = Search.execute('title in:title')