fixes #2049
This commit is contained in:
@@ -170,12 +170,12 @@ class PostQueryBuilder
|
|||||||
if q[:source] == "none%"
|
if q[:source] == "none%"
|
||||||
relation = relation.where("(posts.source = '' OR posts.source IS NULL)")
|
relation = relation.where("(posts.source = '' OR posts.source IS NULL)")
|
||||||
elsif q[:source] == "http%"
|
elsif q[:source] == "http%"
|
||||||
relation = relation.where("(posts.source like ?)", "http%")
|
relation = relation.where("(lower(posts.source) like ?", "http%")
|
||||||
elsif q[:source] =~ /^%\.?pixiv(?:\.net(?:\/img)?)?(?:%\/|(?=%$))(.+)$/
|
elsif q[:source] =~ /^%\.?pixiv(?:\.net(?:\/img)?)?(?:%\/|(?=%$))(.+)$/i
|
||||||
relation = relation.where("SourcePattern(posts.source) LIKE ? ESCAPE E'\\\\'", "pixiv/" + $1)
|
relation = relation.where("SourcePattern(lower(posts.source)) LIKE lower(?) ESCAPE E'\\\\'", "pixiv/" + $1)
|
||||||
has_constraints!
|
has_constraints!
|
||||||
else
|
else
|
||||||
relation = relation.where("SourcePattern(posts.source) LIKE SourcePattern(?) ESCAPE E'\\\\'", q[:source])
|
relation = relation.where("SourcePattern(lower(posts.source)) LIKE SourcePattern(lower(?)) ESCAPE E'\\\\'", q[:source])
|
||||||
has_constraints!
|
has_constraints!
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -184,12 +184,12 @@ class PostQueryBuilder
|
|||||||
if q[:source_neg] == "none%"
|
if q[:source_neg] == "none%"
|
||||||
relation = relation.where("(posts.source != '' AND posts.source IS NOT NULL)")
|
relation = relation.where("(posts.source != '' AND posts.source IS NOT NULL)")
|
||||||
elsif q[:source_neg] == "http%"
|
elsif q[:source_neg] == "http%"
|
||||||
relation = relation.where("(posts.source not like ?)", "http%")
|
relation = relation.where("(lower(posts.source) not like ?)", "http%")
|
||||||
elsif q[:source_neg] =~ /^%\.?pixiv(?:\.net(?:\/img)?)?(?:%\/|(?=%$))(.+)$/
|
elsif q[:source_neg] =~ /^%\.?pixiv(?:\.net(?:\/img)?)?(?:%\/|(?=%$))(.+)$/i
|
||||||
relation = relation.where("SourcePattern(posts.source) NOT LIKE ? ESCAPE E'\\\\'", "pixiv/" + $1)
|
relation = relation.where("SourcePattern(lower(posts.source)) NOT LIKE lower(?) ESCAPE E'\\\\'", "pixiv/" + $1)
|
||||||
has_constraints!
|
has_constraints!
|
||||||
else
|
else
|
||||||
relation = relation.where("SourcePattern(posts.source) NOT LIKE SourcePattern(?) ESCAPE E'\\\\'", q[:source_neg])
|
relation = relation.where("SourcePattern(lower(posts.source)) NOT LIKE SourcePattern(lower(?)) ESCAPE E'\\\\'", q[:source_neg])
|
||||||
has_constraints!
|
has_constraints!
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
21
db/migrate/20140111191413_change_source_index_on_posts.rb
Normal file
21
db/migrate/20140111191413_change_source_index_on_posts.rb
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
class ChangeSourceIndexOnPosts < ActiveRecord::Migration
|
||||||
|
def up
|
||||||
|
execute "set statement_timeout = 0"
|
||||||
|
execute "DROP INDEX index_posts_on_source"
|
||||||
|
execute "DROP INDEX index_posts_on_source_pattern"
|
||||||
|
execute "CREATE INDEX index_posts_on_source ON posts USING btree
|
||||||
|
(lower(source))"
|
||||||
|
execute "CREATE INDEX index_posts_on_source_pattern ON posts USING btree
|
||||||
|
((SourcePattern(lower(source))) text_pattern_ops)"
|
||||||
|
end
|
||||||
|
|
||||||
|
def down
|
||||||
|
execute "set statement_timeout = 0"
|
||||||
|
execute "DROP INDEX index_posts_on_source"
|
||||||
|
execute "DROP INDEX index_posts_on_source_pattern"
|
||||||
|
execute "CREATE INDEX index_posts_on_source ON posts USING btree
|
||||||
|
(source)"
|
||||||
|
execute "CREATE INDEX index_posts_on_source_pattern ON posts USING btree
|
||||||
|
((SourcePattern(source)) text_pattern_ops)"
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -1206,10 +1206,10 @@ class PostTest < ActiveSupport::TestCase
|
|||||||
assert_equal(post2.id, relation.first.id)
|
assert_equal(post2.id, relation.first.id)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "return posts for a case sensitive source search" do
|
should "return posts for a case insensitive source search" do
|
||||||
post1 = FactoryGirl.create(:post, :source => "ABCD")
|
post1 = FactoryGirl.create(:post, :source => "ABCD")
|
||||||
post2 = FactoryGirl.create(:post, :source => "1234")
|
post2 = FactoryGirl.create(:post, :source => "1234")
|
||||||
relation = Post.tag_match("source:ABCD")
|
relation = Post.tag_match("source:abcd")
|
||||||
assert_equal(1, relation.count)
|
assert_equal(1, relation.count)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user