search: make order:random truly random; add random:N metatag.
Make the `order:random` metatag truly randomize the search. Add a `random:N` metatag that returns up to N random posts, like what `order:random` did before. `order:random` now returns the entire search in random order. Before it just returned a pageful of pseudorandom posts. This will be more accurate for small searches, but slower for large searches. If `order:random` times out, try `random:N` instead. The `random:N` metatag returns up to N pseudorandom posts. This is faster than `order:random` for large searches, but for small searches, it may return less than N posts, and the randomness may be biased. Some posts may be more likely than others to appear. N must be between 0 and 200. Also, `/posts?tags=touhou&random=1` now redirects to `/posts?tags=touhou+random:N`. Before the `random=1` param acted like a free `order:random` tag; now it redirects to a `random:N` search, so it counts against your tag limit.
This commit is contained in:
@@ -1099,6 +1099,14 @@ class PostQueryBuilderTest < ActiveSupport::TestCase
|
||||
assert_tag_match([], "exif:DNE")
|
||||
end
|
||||
|
||||
should "return posts for the random:<N> metatag" do
|
||||
post = create(:post)
|
||||
|
||||
assert_tag_match([], "random:0")
|
||||
assert_tag_match([post], "random:1")
|
||||
assert_tag_match([post], "random:1000")
|
||||
end
|
||||
|
||||
should "return posts ordered by a particular attribute" do
|
||||
posts = (1..2).map do |n|
|
||||
tags = ["tagme", "gentag1 gentag2 artist:arttag char:chartag copy:copytag"]
|
||||
@@ -1210,6 +1218,12 @@ class PostQueryBuilderTest < ActiveSupport::TestCase
|
||||
end
|
||||
end
|
||||
|
||||
should "return posts for order:random" do
|
||||
post = create(:post)
|
||||
|
||||
assert_tag_match([post], "order:random")
|
||||
end
|
||||
|
||||
should "return posts for a filesize search" do
|
||||
post = create(:post, file_size: 1.megabyte)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user