fixes #775
This commit is contained in:
@@ -144,7 +144,7 @@ class Tag < ActiveRecord::Base
|
|||||||
|
|
||||||
module ParseMethods
|
module ParseMethods
|
||||||
def normalize(query)
|
def normalize(query)
|
||||||
query.to_s.downcase.strip
|
query.to_s.strip
|
||||||
end
|
end
|
||||||
|
|
||||||
def scan_query(query)
|
def scan_query(query)
|
||||||
@@ -219,18 +219,18 @@ class Tag < ActiveRecord::Base
|
|||||||
|
|
||||||
def parse_tag(tag, output)
|
def parse_tag(tag, output)
|
||||||
if tag[0] == "-" && tag.size > 1
|
if tag[0] == "-" && tag.size > 1
|
||||||
output[:exclude] << tag[1..-1]
|
output[:exclude] << tag[1..-1].downcase
|
||||||
|
|
||||||
elsif tag[0] == "~" && tag.size > 1
|
elsif tag[0] == "~" && tag.size > 1
|
||||||
output[:include] << tag[1..-1]
|
output[:include] << tag[1..-1].downcase
|
||||||
|
|
||||||
elsif tag =~ /\*/
|
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?
|
matches = ["~no_matches~"] if matches.empty?
|
||||||
output[:include] += matches
|
output[:include] += matches
|
||||||
|
|
||||||
else
|
else
|
||||||
output[:related] << tag
|
output[:related] << tag.downcase
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -283,7 +283,7 @@ class Tag < ActiveRecord::Base
|
|||||||
q[:subscriptions] << $2
|
q[:subscriptions] << $2
|
||||||
|
|
||||||
when "md5"
|
when "md5"
|
||||||
q[:md5] = $2.split(/,/)
|
q[:md5] = $2.downcase.split(/,/)
|
||||||
|
|
||||||
when "-rating"
|
when "-rating"
|
||||||
q[:rating_negated] = $2
|
q[:rating_negated] = $2
|
||||||
@@ -334,10 +334,10 @@ class Tag < ActiveRecord::Base
|
|||||||
q[:parent_id] = $2.to_i
|
q[:parent_id] = $2.to_i
|
||||||
|
|
||||||
when "order"
|
when "order"
|
||||||
q[:order] = $2
|
q[:order] = $2.downcase
|
||||||
|
|
||||||
when "status"
|
when "status"
|
||||||
q[:status] = $2
|
q[:status] = $2.downcase
|
||||||
|
|
||||||
when "pixiv"
|
when "pixiv"
|
||||||
q[:pixiv] = parse_helper($2)
|
q[:pixiv] = parse_helper($2)
|
||||||
|
|||||||
@@ -111,7 +111,7 @@ class TagSubscription < ActiveRecord::Base
|
|||||||
relation = where("creator_id = ?", user_id)
|
relation = where("creator_id = ?", user_id)
|
||||||
|
|
||||||
if name
|
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
|
end
|
||||||
|
|
||||||
relation.each do |tag_sub|
|
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);
|
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:
|
-- Name: index_pools_on_name; Type: INDEX; Schema: public; Owner: -; Tablespace:
|
||||||
--
|
--
|
||||||
@@ -6232,3 +6239,5 @@ INSERT INTO schema_migrations (version) VALUES ('20130302214500');
|
|||||||
INSERT INTO schema_migrations (version) VALUES ('20130305005138');
|
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)
|
assert_equal(post2.id, relation.first.id)
|
||||||
end
|
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
|
should "return posts for a pixiv source search" do
|
||||||
post = FactoryGirl.create(:post, :source => "http://i1.pixiv.net/img123/img/artist-name/789.png")
|
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)
|
assert_equal(1, Post.tag_match("source:pixiv/artist-name/*").count)
|
||||||
|
|||||||
@@ -101,12 +101,12 @@ class TagTest < ActiveSupport::TestCase
|
|||||||
context "A tag parser" do
|
context "A tag parser" do
|
||||||
should "scan a query" 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"))
|
||||||
assert_equal(%w(~aaa -bbb*), Tag.scan_query("~AAa -BBB* -bbb*"))
|
assert_equal(%w(~AAa -BBB* -bbb*), Tag.scan_query("~AAa -BBB* -bbb*"))
|
||||||
end
|
end
|
||||||
|
|
||||||
should "strip out invalid characters when scanning" do
|
should "strip out invalid characters when scanning" do
|
||||||
assert_equal(%w(aaa bbb), Tag.scan_tags("aaa bbb"))
|
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
|
end
|
||||||
|
|
||||||
should "cast values" do
|
should "cast values" do
|
||||||
|
|||||||
Reference in New Issue
Block a user