search: fix order:custom metatag.
Fix order:custom not working. Also change order:custom to return no
posts under the following error conditions:
* {{order:custom}} (id metatag isn't present)
* {{id:42 order:custom}} (id metatag isn't a list)
* {{id:>42 order:custom}} (id metatag isn't a list)
* {{id:1,2 id:2,3 order:custom}} (id metatag is present twice)
This commit is contained in:
@@ -607,8 +607,8 @@ class PostQueryBuilder
|
||||
relation = relation.where("posts.image_width IS NOT NULL and posts.image_height IS NOT NULL")
|
||||
end
|
||||
|
||||
if q[:order] == "custom" && q[:post_id].present? && q[:post_id][0] == :in
|
||||
relation = relation.find_ordered(q[:post_id][1])
|
||||
if q[:order] == "custom"
|
||||
relation = search_order_custom(relation, q[:id])
|
||||
else
|
||||
relation = search_order(relation, q[:order])
|
||||
end
|
||||
@@ -739,6 +739,15 @@ class PostQueryBuilder
|
||||
relation
|
||||
end
|
||||
|
||||
def search_order_custom(relation, id_metatags)
|
||||
return relation.none unless id_metatags.present? && id_metatags.size == 1
|
||||
|
||||
operator, ids = parse_range(id_metatags.first, :integer)
|
||||
return relation.none unless operator == :in
|
||||
|
||||
relation.find_ordered(ids)
|
||||
end
|
||||
|
||||
concerning :ParseMethods do
|
||||
def scan_query
|
||||
terms = []
|
||||
|
||||
@@ -809,6 +809,20 @@ class PostQueryBuilderTest < ActiveSupport::TestCase
|
||||
assert_tag_match([post2, post1, post3], "order:comment_bumped_asc")
|
||||
end
|
||||
|
||||
should "return posts for order:custom" do
|
||||
p1 = create(:post)
|
||||
p2 = create(:post)
|
||||
p3 = create(:post)
|
||||
|
||||
as(create(:gold_user)) do
|
||||
assert_tag_match([p2, p1, p3], "id:#{p2.id},#{p1.id},#{p3.id} order:custom")
|
||||
assert_tag_match([], "id:#{p1.id} order:custom")
|
||||
assert_tag_match([], "id:>0 order:custom")
|
||||
assert_tag_match([], "id:1,2 id:2,3 order:custom")
|
||||
assert_tag_match([], "order:custom")
|
||||
end
|
||||
end
|
||||
|
||||
should "return posts for a filesize search" do
|
||||
post = create(:post, file_size: 1.megabyte)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user