search: add synonyms for *_count metatags.
Allow e.g. `deleted_comments` as a synonym for `deleted_comment_count`.
This commit is contained in:
@@ -8,6 +8,10 @@ class Tag < ApplicationRecord
|
|||||||
pool_count deleted_pool_count active_pool_count series_pool_count collection_pool_count
|
pool_count deleted_pool_count active_pool_count series_pool_count collection_pool_count
|
||||||
appeal_count approval_count replacement_count
|
appeal_count approval_count replacement_count
|
||||||
]
|
]
|
||||||
|
|
||||||
|
# allow e.g. `deleted_comments` as a synonym for `deleted_comment_count`
|
||||||
|
COUNT_METATAG_SYNONYMS = COUNT_METATAGS.map { |str| str.delete_suffix("_count").pluralize }
|
||||||
|
|
||||||
METATAGS = %w[
|
METATAGS = %w[
|
||||||
-user user -approver approver commenter comm noter noteupdater artcomm
|
-user user -approver approver commenter comm noter noteupdater artcomm
|
||||||
-pool pool ordpool -favgroup favgroup -fav fav ordfav md5 -rating rating
|
-pool pool ordpool -favgroup favgroup -fav fav ordfav md5 -rating rating
|
||||||
@@ -15,7 +19,7 @@ class Tag < ApplicationRecord
|
|||||||
-source id -id date age order limit -status status tagcount parent -parent
|
-source id -id date age order limit -status status tagcount parent -parent
|
||||||
child pixiv_id pixiv search upvote downvote filetype -filetype flagger
|
child pixiv_id pixiv search upvote downvote filetype -filetype flagger
|
||||||
-flagger appealer -appealer disapproval -disapproval
|
-flagger appealer -appealer disapproval -disapproval
|
||||||
] + TagCategory.short_name_list.map {|x| "#{x}tags"} + COUNT_METATAGS
|
] + TagCategory.short_name_list.map {|x| "#{x}tags"} + COUNT_METATAGS + COUNT_METATAG_SYNONYMS
|
||||||
|
|
||||||
SUBQUERY_METATAGS = %w[commenter comm noter noteupdater artcomm flagger -flagger appealer -appealer]
|
SUBQUERY_METATAGS = %w[commenter comm noter noteupdater artcomm flagger -flagger appealer -appealer]
|
||||||
|
|
||||||
@@ -764,7 +768,14 @@ class Tag < ApplicationRecord
|
|||||||
q[:child] = g2.downcase
|
q[:child] = g2.downcase
|
||||||
|
|
||||||
when "order"
|
when "order"
|
||||||
q[:order] = g2.downcase
|
g2 = g2.downcase
|
||||||
|
|
||||||
|
order, suffix, _ = g2.partition(/_(asc|desc)\z/i)
|
||||||
|
if order.in?(COUNT_METATAG_SYNONYMS)
|
||||||
|
g2 = order.singularize + "_count" + suffix
|
||||||
|
end
|
||||||
|
|
||||||
|
q[:order] = g2
|
||||||
|
|
||||||
when "limit"
|
when "limit"
|
||||||
# Do nothing. The controller takes care of it.
|
# Do nothing. The controller takes care of it.
|
||||||
@@ -801,6 +812,10 @@ class Tag < ApplicationRecord
|
|||||||
when *COUNT_METATAGS
|
when *COUNT_METATAGS
|
||||||
q[g1.to_sym] = parse_helper(g2)
|
q[g1.to_sym] = parse_helper(g2)
|
||||||
|
|
||||||
|
when *COUNT_METATAG_SYNONYMS
|
||||||
|
g1 = "#{g1.singularize}_count"
|
||||||
|
q[g1.to_sym] = parse_helper(g2)
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -2111,6 +2111,10 @@ class PostTest < ActiveSupport::TestCase
|
|||||||
assert_tag_match([posts[1], posts[0]], "note_count:1")
|
assert_tag_match([posts[1], posts[0]], "note_count:1")
|
||||||
assert_tag_match([posts[0]], "active_note_count:1")
|
assert_tag_match([posts[0]], "active_note_count:1")
|
||||||
assert_tag_match([posts[1]], "deleted_note_count:1")
|
assert_tag_match([posts[1]], "deleted_note_count:1")
|
||||||
|
|
||||||
|
assert_tag_match([posts[1], posts[0]], "notes:1")
|
||||||
|
assert_tag_match([posts[0]], "active_notes:1")
|
||||||
|
assert_tag_match([posts[1]], "deleted_notes:1")
|
||||||
end
|
end
|
||||||
|
|
||||||
should "return posts for the artcomm:<name> metatag" do
|
should "return posts for the artcomm:<name> metatag" do
|
||||||
@@ -2418,6 +2422,8 @@ class PostTest < ActiveSupport::TestCase
|
|||||||
assert_tag_match(posts.reverse, "order:rank")
|
assert_tag_match(posts.reverse, "order:rank")
|
||||||
assert_tag_match(posts.reverse, "order:note_count")
|
assert_tag_match(posts.reverse, "order:note_count")
|
||||||
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_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")
|
||||||
@@ -2436,6 +2442,7 @@ class PostTest < ActiveSupport::TestCase
|
|||||||
assert_tag_match(posts, "order:chartags_asc")
|
assert_tag_match(posts, "order:chartags_asc")
|
||||||
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")
|
||||||
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