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[
|
ORDER_METATAGS = %w[
|
||||||
id id_desc
|
id id_desc
|
||||||
|
md5 md5_asc
|
||||||
score score_asc
|
score score_asc
|
||||||
favcount favcount_asc
|
favcount favcount_asc
|
||||||
created_at created_at_asc
|
created_at created_at_asc
|
||||||
@@ -81,6 +82,7 @@ class PostQueryBuilder
|
|||||||
modqueue
|
modqueue
|
||||||
random
|
random
|
||||||
custom
|
custom
|
||||||
|
none
|
||||||
] +
|
] +
|
||||||
COUNT_METATAGS +
|
COUNT_METATAGS +
|
||||||
COUNT_METATAG_SYNONYMS.flat_map { |str| [str, "#{str}_asc"] } +
|
COUNT_METATAG_SYNONYMS.flat_map { |str| [str, "#{str}_asc"] } +
|
||||||
@@ -561,6 +563,12 @@ class PostQueryBuilder
|
|||||||
when "id_desc"
|
when "id_desc"
|
||||||
relation = relation.order("posts.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"
|
when "score", "score_desc"
|
||||||
relation = relation.order("posts.score DESC, posts.id DESC")
|
relation = relation.order("posts.score DESC, posts.id DESC")
|
||||||
|
|
||||||
@@ -672,6 +680,9 @@ class PostQueryBuilder
|
|||||||
when "modqueue_asc"
|
when "modqueue_asc"
|
||||||
relation = relation.left_outer_joins(:flags).order(Arel.sql("GREATEST(posts.created_at, post_flags.created_at) ASC, posts.id 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
|
else
|
||||||
relation = relation.order("posts.id DESC")
|
relation = relation.order("posts.id DESC")
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -763,6 +763,7 @@ class PostQueryBuilderTest < ActiveSupport::TestCase
|
|||||||
p = create(
|
p = create(
|
||||||
:post,
|
:post,
|
||||||
score: n,
|
score: n,
|
||||||
|
md5: n.to_s,
|
||||||
fav_count: n,
|
fav_count: n,
|
||||||
file_size: 1.megabyte * n,
|
file_size: 1.megabyte * n,
|
||||||
# posts[0] is portrait, posts[1] is landscape. posts[1].mpixels > posts[0].mpixels.
|
# 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:note_count_desc")
|
||||||
assert_tag_match(posts.reverse, "order:notes")
|
assert_tag_match(posts.reverse, "order:notes")
|
||||||
assert_tag_match(posts.reverse, "order:notes_desc")
|
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:id_asc")
|
||||||
assert_tag_match(posts, "order:score_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:copytags_asc")
|
||||||
assert_tag_match(posts, "order:note_count_asc")
|
assert_tag_match(posts, "order:note_count_asc")
|
||||||
assert_tag_match(posts, "order:notes_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
|
end
|
||||||
|
|
||||||
should "return posts for order:comment_bumped" do
|
should "return posts for order:comment_bumped" do
|
||||||
|
|||||||
Reference in New Issue
Block a user