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:
evazion
2020-04-23 21:14:38 -05:00
parent 009b5ad84c
commit 627f079e3f
2 changed files with 25 additions and 2 deletions

View File

@@ -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 = []