Add more cases for normalizing pixiv source searches

This commit is contained in:
Toks
2014-10-25 15:49:59 -04:00
parent ebd3ece4e8
commit 3194df7e85
2 changed files with 4 additions and 2 deletions

View File

@@ -174,7 +174,7 @@ class PostQueryBuilder
relation = relation.where("(posts.source = '' OR posts.source IS NULL)")
elsif q[:source] == "http%"
relation = relation.where("(lower(posts.source) like ?)", "http%")
elsif q[:source] =~ /^%\.?pixiv(?:\.net(?:\/img)?)?(?:%\/|(?=%$))(.+)$/i
elsif q[:source] =~ /^(?:https?:\/\/)?%\.?pixiv(?:\.net(?:\/img)?)?(?:%\/img\/|%\/|(?=%$))(.+)$/i
relation = relation.where("SourcePattern(lower(posts.source)) LIKE lower(?) ESCAPE E'\\\\'", "pixiv/" + $1)
has_constraints!
else
@@ -188,7 +188,7 @@ class PostQueryBuilder
relation = relation.where("(posts.source != '' AND posts.source IS NOT NULL)")
elsif q[:source_neg] == "http%"
relation = relation.where("(lower(posts.source) not like ?)", "http%")
elsif q[:source_neg] =~ /^%\.?pixiv(?:\.net(?:\/img)?)?(?:%\/|(?=%$))(.+)$/i
elsif q[:source_neg] =~ /^(?:https?:\/\/)?%\.?pixiv(?:\.net(?:\/img)?)?(?:%\/img\/|%\/|(?=%$))(.+)$/i
relation = relation.where("SourcePattern(lower(posts.source)) NOT LIKE lower(?) ESCAPE E'\\\\'", "pixiv/" + $1)
has_constraints!
else

View File

@@ -1218,6 +1218,8 @@ class PostTest < ActiveSupport::TestCase
post = FactoryGirl.create(:post, :source => url)
assert_equal(1, Post.tag_match("source:*.pixiv.net/img*/artist-name/*").count)
assert_equal(0, Post.tag_match("source:*.pixiv.net/img*/artist-fake/*").count)
assert_equal(1, Post.tag_match("source:http://*.pixiv.net/img*/img/artist-name/*").count)
assert_equal(0, Post.tag_match("source:http://*.pixiv.net/img*/img/artist-fake/*").count)
assert_equal(1, Post.tag_match("source:pixiv/artist-name/*").count)
assert_equal(0, Post.tag_match("source:pixiv/artist-fake/*").count)
end