FEATURE: min_age and max_age search operators
This commit is contained in:
parent
f101408d03
commit
e85df6b876
|
@ -2411,7 +2411,8 @@ 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><td colspan=4></td></tr>
|
||||
<tr><td><code>in:bookmarks</code><td colspan=4></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>
|
||||
<p>
|
||||
|
|
|
@ -219,6 +219,16 @@ class Search
|
|||
posts.where("posts.user_id = #{user_id}")
|
||||
end
|
||||
|
||||
advanced_filter(/min_age:(\d+)/) do |posts,match|
|
||||
n = match.to_i
|
||||
posts.where("topics.created_at > ?", n.days.ago)
|
||||
end
|
||||
|
||||
advanced_filter(/max_age:(\d+)/) do |posts,match|
|
||||
n = match.to_i
|
||||
posts.where("topics.created_at < ?", n.days.ago)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
|
||||
|
|
|
@ -372,6 +372,18 @@ describe Search do
|
|||
end
|
||||
|
||||
describe 'Advanced search' do
|
||||
|
||||
it 'supports min_age and max_age' do
|
||||
topic = Fabricate(:topic, created_at: 3.months.ago)
|
||||
Fabricate(:post, raw: 'hi this is a test 123 123', 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)
|
||||
|
||||
end
|
||||
|
||||
it 'can find by status' do
|
||||
post = Fabricate(:post, raw: 'hi this is a test 123 123')
|
||||
topic = post.topic
|
||||
|
|
Loading…
Reference in New Issue