FEATURE: in:first for searching first post

This commit is contained in:
Sam 2015-06-23 13:39:40 +10:00
parent e85df6b876
commit 63351d5629
3 changed files with 10 additions and 2 deletions

View File

@ -2411,7 +2411,7 @@ en:
<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:singleuser</code></td></tr>
<tr><td><code>category:foo</code></td><td><code>user:foo</code></td><td colspan=3></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 colspan=4></td></tr>
<tr><td><code>in:bookmarks</code></td><td><code>in:first</code></td><td colspan=3></td></tr>
<tr><td><code>posts_count:num</code></td><td><code>min_age:days</code></td><td><code>max_age:days</code></td> <td colspan=2></td></tr>
</table>
</p>

View File

@ -179,6 +179,9 @@ class Search
posts.where("topics.posts_count = ?", match.to_i)
end
advanced_filter(/in:first/) do |posts|
posts.where("posts.post_number = 1")
end
advanced_filter(/in:(likes|bookmarks)/) do |posts, match|
if @guardian.user

View File

@ -373,15 +373,20 @@ describe Search do
describe 'Advanced search' do
it 'supports min_age and max_age' do
it 'supports min_age and max_age in:first' do
topic = Fabricate(:topic, created_at: 3.months.ago)
Fabricate(:post, raw: 'hi this is a test 123 123', topic: topic)
Fabricate(:post, raw: 'boom boom shake the room', topic: topic)
expect(Search.execute('test min_age:100').posts.length).to eq(1)
expect(Search.execute('test min_age:10').posts.length).to eq(0)
expect(Search.execute('test max_age:10').posts.length).to eq(1)
expect(Search.execute('test max_age:100').posts.length).to eq(0)
expect(Search.execute('test in:first').posts.length).to eq(1)
expect(Search.execute('boom').posts.length).to eq(1)
expect(Search.execute('boom in:first').posts.length).to eq(0)
end
it 'can find by status' do