fixes #775
This commit is contained in:
@@ -144,7 +144,7 @@ class Tag < ActiveRecord::Base
|
||||
|
||||
module ParseMethods
|
||||
def normalize(query)
|
||||
query.to_s.downcase.strip
|
||||
query.to_s.strip
|
||||
end
|
||||
|
||||
def scan_query(query)
|
||||
@@ -219,18 +219,18 @@ class Tag < ActiveRecord::Base
|
||||
|
||||
def parse_tag(tag, output)
|
||||
if tag[0] == "-" && tag.size > 1
|
||||
output[:exclude] << tag[1..-1]
|
||||
output[:exclude] << tag[1..-1].downcase
|
||||
|
||||
elsif tag[0] == "~" && tag.size > 1
|
||||
output[:include] << tag[1..-1]
|
||||
output[:include] << tag[1..-1].downcase
|
||||
|
||||
elsif tag =~ /\*/
|
||||
matches = Tag.name_matches(tag).all(:select => "name", :limit => Danbooru.config.tag_query_limit, :order => "post_count DESC").map(&:name)
|
||||
matches = Tag.name_matches(tag.downcase).all(:select => "name", :limit => Danbooru.config.tag_query_limit, :order => "post_count DESC").map(&:name)
|
||||
matches = ["~no_matches~"] if matches.empty?
|
||||
output[:include] += matches
|
||||
|
||||
else
|
||||
output[:related] << tag
|
||||
output[:related] << tag.downcase
|
||||
end
|
||||
end
|
||||
|
||||
@@ -283,7 +283,7 @@ class Tag < ActiveRecord::Base
|
||||
q[:subscriptions] << $2
|
||||
|
||||
when "md5"
|
||||
q[:md5] = $2.split(/,/)
|
||||
q[:md5] = $2.downcase.split(/,/)
|
||||
|
||||
when "-rating"
|
||||
q[:rating_negated] = $2
|
||||
@@ -334,10 +334,10 @@ class Tag < ActiveRecord::Base
|
||||
q[:parent_id] = $2.to_i
|
||||
|
||||
when "order"
|
||||
q[:order] = $2
|
||||
q[:order] = $2.downcase
|
||||
|
||||
when "status"
|
||||
q[:status] = $2
|
||||
q[:status] = $2.downcase
|
||||
|
||||
when "pixiv"
|
||||
q[:pixiv] = parse_helper($2)
|
||||
|
||||
@@ -111,7 +111,7 @@ class TagSubscription < ActiveRecord::Base
|
||||
relation = where("creator_id = ?", user_id)
|
||||
|
||||
if name
|
||||
relation = relation.where("name ILIKE ? ESCAPE E'\\\\'", name.to_escaped_for_sql_like)
|
||||
relation = relation.where("lower(name) LIKE ? ESCAPE E'\\\\'", name.downcase.to_escaped_for_sql_like)
|
||||
end
|
||||
|
||||
relation.each do |tag_sub|
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
class AddLowerNameIndexToPools < ActiveRecord::Migration
|
||||
def self.up
|
||||
execute "create index index_pools_on_lower_name on pools (lower(name))"
|
||||
end
|
||||
|
||||
def self.down
|
||||
execute "drop index index_pools_on_lower_name"
|
||||
end
|
||||
end
|
||||
@@ -5679,6 +5679,13 @@ CREATE INDEX index_pool_versions_on_updater_ip_addr ON pool_versions USING btree
|
||||
CREATE INDEX index_pools_on_creator_id ON pools USING btree (creator_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_pools_on_lower_name; Type: INDEX; Schema: public; Owner: -; Tablespace:
|
||||
--
|
||||
|
||||
CREATE INDEX index_pools_on_lower_name ON pools USING btree (lower((name)::text));
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_pools_on_name; Type: INDEX; Schema: public; Owner: -; Tablespace:
|
||||
--
|
||||
@@ -6231,4 +6238,6 @@ INSERT INTO schema_migrations (version) VALUES ('20130302214500');
|
||||
|
||||
INSERT INTO schema_migrations (version) VALUES ('20130305005138');
|
||||
|
||||
INSERT INTO schema_migrations (version) VALUES ('20130307225324');
|
||||
INSERT INTO schema_migrations (version) VALUES ('20130307225324');
|
||||
|
||||
INSERT INTO schema_migrations (version) VALUES ('20130308204213');
|
||||
@@ -909,6 +909,13 @@ class PostTest < ActiveSupport::TestCase
|
||||
assert_equal(post2.id, relation.first.id)
|
||||
end
|
||||
|
||||
should "return posts for a case sensitive source search" do
|
||||
post1 = FactoryGirl.create(:post, :source => "ABCD")
|
||||
post2 = FactoryGirl.create(:post, :source => "1234")
|
||||
relation = Post.tag_match("source:ABCD")
|
||||
assert_equal(1, relation.count)
|
||||
end
|
||||
|
||||
should "return posts for a pixiv source search" do
|
||||
post = FactoryGirl.create(:post, :source => "http://i1.pixiv.net/img123/img/artist-name/789.png")
|
||||
assert_equal(1, Post.tag_match("source:pixiv/artist-name/*").count)
|
||||
|
||||
@@ -101,12 +101,12 @@ class TagTest < ActiveSupport::TestCase
|
||||
context "A tag parser" do
|
||||
should "scan a query" do
|
||||
assert_equal(%w(aaa bbb), Tag.scan_query("aaa bbb"))
|
||||
assert_equal(%w(~aaa -bbb*), Tag.scan_query("~AAa -BBB* -bbb*"))
|
||||
assert_equal(%w(~AAa -BBB* -bbb*), Tag.scan_query("~AAa -BBB* -bbb*"))
|
||||
end
|
||||
|
||||
should "strip out invalid characters when scanning" do
|
||||
assert_equal(%w(aaa bbb), Tag.scan_tags("aaa bbb"))
|
||||
assert_equal(%w(-bb;b* -b_b_b_), Tag.scan_tags("-B,B;B* -b_b_b_"))
|
||||
assert_equal(%w(-BB;B* -b_b_b_), Tag.scan_tags("-B,B;B* -b_b_b_"))
|
||||
end
|
||||
|
||||
should "cast values" do
|
||||
|
||||
Reference in New Issue
Block a user