diff --git a/app/logical/post_query_builder.rb b/app/logical/post_query_builder.rb index f92bb834f..3a67ce3bd 100644 --- a/app/logical/post_query_builder.rb +++ b/app/logical/post_query_builder.rb @@ -122,7 +122,6 @@ class PostQueryBuilder relation = add_range_relation(q["#{category}_tag_count".to_sym], "posts.tag_count_#{category}", relation) end relation = add_range_relation(q[:post_tag_count], "posts.tag_count", relation) - relation = add_range_relation(q[:pixiv_id], "posts.pixiv_id", relation) if q[:md5] relation = relation.where(["posts.md5 IN (?)", q[:md5]]) @@ -327,6 +326,16 @@ class PostQueryBuilder relation = relation.where("posts.has_children = TRUE") end + if q[:pixiv_id] + if q[:pixiv_id] == "any" + relation = relation.where("posts.pixiv_id IS NOT NULL") + elsif q[:pixiv_id] == "none" + relation = relation.where("posts.pixiv_id IS NULL") + else + relation = add_range_relation(q[:pixiv_id], "posts.pixiv_id", relation) + end + end + if q[:rating] =~ /^q/ relation = relation.where("posts.rating = 'q'") elsif q[:rating] =~ /^s/ diff --git a/app/models/tag.rb b/app/models/tag.rb index 8ab7e0195..85ec7894f 100644 --- a/app/models/tag.rb +++ b/app/models/tag.rb @@ -763,7 +763,11 @@ class Tag < ApplicationRecord q[:filetype_neg] = g2.downcase when "pixiv_id", "pixiv" - q[:pixiv_id] = parse_helper(g2) + if g2.downcase == "any" || g2.downcase == "none" + q[:pixiv_id] = g2.downcase + else + q[:pixiv_id] = parse_helper(g2) + end when "upvote" if CurrentUser.user.is_moderator? diff --git a/test/unit/post_test.rb b/test/unit/post_test.rb index 4fa6cd847..b01ed3a2c 100644 --- a/test/unit/post_test.rb +++ b/test/unit/post_test.rb @@ -2223,19 +2223,30 @@ class PostTest < ActiveSupport::TestCase post = FactoryBot.create(:post, :source => url) assert_tag_match([post], "pixiv_id:789") end - + should "return posts for a pixiv id search (type 3)" do url = "http://www.pixiv.net/member_illust.php?mode=manga_big&illust_id=19113635&page=0" post = FactoryBot.create(:post, :source => url) assert_tag_match([post], "pixiv_id:19113635") end - + should "return posts for a pixiv id search (type 4)" do url = "http://i2.pixiv.net/img70/img/disappearedstump/34551381_p3.jpg?1364424318" post = FactoryBot.create(:post, :source => url) assert_tag_match([post], "pixiv_id:34551381") end - + + should "return posts for a pixiv_id:any search" do + url = "http://i1.pixiv.net/img-original/img/2014/10/02/13/51/23/46304396_p0.png" + post = FactoryBot.create(:post, source: url) + assert_tag_match([post], "pixiv_id:any") + end + + should "return posts for a pixiv_id:none search" do + post = FactoryBot.create(:post) + assert_tag_match([post], "pixiv_id:none") + end + # should "return posts for a pixiv novel id search" do # url = "http://www.pixiv.net/novel/show.php?id=2156088" # post = FactoryBot.create(:post, :source => url)