diff --git a/app/logical/post_query/parser.rb b/app/logical/post_query/parser.rb index 5f8f631ca..c09cd36a6 100644 --- a/app/logical/post_query/parser.rb +++ b/app/logical/post_query/parser.rb @@ -165,6 +165,14 @@ class PostQuery name = @scanner.matched.delete_suffix(":").downcase name = name.singularize + "_count" if name.in?(PostQueryBuilder::COUNT_METATAG_SYNONYMS) quoted, value = quoted_string + + if name == "order" + attribute, direction, _tail = value.to_s.downcase.partition(/_(asc|desc)\z/i) + if attribute.in?(PostQueryBuilder::COUNT_METATAG_SYNONYMS) + value = attribute.singularize + "_count" + direction + end + end + node(:metatag, name, value, quoted) end end diff --git a/test/unit/post_query_parser_test.rb b/test/unit/post_query_parser_test.rb index 328df2d4c..4301f226c 100644 --- a/test/unit/post_query_parser_test.rb +++ b/test/unit/post_query_parser_test.rb @@ -98,6 +98,15 @@ class PostQueryParserTest < ActiveSupport::TestCase assert_parse_equals("appeal_count:0", "appeals:0") assert_parse_equals("approval_count:0", "approvals:0") assert_parse_equals("replacement_count:0", "replacements:0") + + assert_parse_equals("order:comment_count", "order:comments") + assert_parse_equals("order:note_count", "order:notes") + assert_parse_equals("order:flag_count", "order:flags") + assert_parse_equals("order:child_count", "order:children") + assert_parse_equals("order:pool_count", "order:pools") + assert_parse_equals("order:appeal_count", "order:appeals") + assert_parse_equals("order:approval_count", "order:approvals") + assert_parse_equals("order:replacement_count", "order:replacements") end should "parse wildcard tags correctly" do