search: add order:md5, order:none metatags.
These may be useful for fast pseudo-random shufflings of search results.
This commit is contained in:
@@ -64,6 +64,7 @@ class PostQueryBuilder
|
||||
|
||||
ORDER_METATAGS = %w[
|
||||
id id_desc
|
||||
md5 md5_asc
|
||||
score score_asc
|
||||
favcount favcount_asc
|
||||
created_at created_at_asc
|
||||
@@ -81,6 +82,7 @@ class PostQueryBuilder
|
||||
modqueue
|
||||
random
|
||||
custom
|
||||
none
|
||||
] +
|
||||
COUNT_METATAGS +
|
||||
COUNT_METATAG_SYNONYMS.flat_map { |str| [str, "#{str}_asc"] } +
|
||||
@@ -561,6 +563,12 @@ class PostQueryBuilder
|
||||
when "id_desc"
|
||||
relation = relation.order("posts.id DESC")
|
||||
|
||||
when "md5", "md5_desc"
|
||||
relation = relation.order("posts.md5 DESC")
|
||||
|
||||
when "md5_asc"
|
||||
relation = relation.order("posts.md5 ASC")
|
||||
|
||||
when "score", "score_desc"
|
||||
relation = relation.order("posts.score DESC, posts.id DESC")
|
||||
|
||||
@@ -672,6 +680,9 @@ class PostQueryBuilder
|
||||
when "modqueue_asc"
|
||||
relation = relation.left_outer_joins(:flags).order(Arel.sql("GREATEST(posts.created_at, post_flags.created_at) ASC, posts.id ASC"))
|
||||
|
||||
when "none"
|
||||
relation = relation.reorder(nil)
|
||||
|
||||
else
|
||||
relation = relation.order("posts.id DESC")
|
||||
end
|
||||
|
||||
@@ -763,6 +763,7 @@ class PostQueryBuilderTest < ActiveSupport::TestCase
|
||||
p = create(
|
||||
:post,
|
||||
score: n,
|
||||
md5: n.to_s,
|
||||
fav_count: n,
|
||||
file_size: 1.megabyte * n,
|
||||
# posts[0] is portrait, posts[1] is landscape. posts[1].mpixels > posts[0].mpixels.
|
||||
@@ -801,6 +802,8 @@ class PostQueryBuilderTest < ActiveSupport::TestCase
|
||||
assert_tag_match(posts.reverse, "order:note_count_desc")
|
||||
assert_tag_match(posts.reverse, "order:notes")
|
||||
assert_tag_match(posts.reverse, "order:notes_desc")
|
||||
assert_tag_match(posts.reverse, "order:md5")
|
||||
assert_tag_match(posts.reverse, "order:md5_desc")
|
||||
|
||||
assert_tag_match(posts, "order:id_asc")
|
||||
assert_tag_match(posts, "order:score_asc")
|
||||
@@ -820,6 +823,10 @@ class PostQueryBuilderTest < ActiveSupport::TestCase
|
||||
assert_tag_match(posts, "order:copytags_asc")
|
||||
assert_tag_match(posts, "order:note_count_asc")
|
||||
assert_tag_match(posts, "order:notes_asc")
|
||||
assert_tag_match(posts, "order:md5_asc")
|
||||
|
||||
# ordering is unpredictable so can't be tested.
|
||||
assert_tag_match([posts.first], "id:#{posts.first.id} order:none")
|
||||
end
|
||||
|
||||
should "return posts for order:comment_bumped" do
|
||||
|
||||
Reference in New Issue
Block a user