Merge pull request #3353 from BrokenEagle/feat-add-meta-tag-category
Migrated tag logic into config file and added fifth tag category meta
This commit is contained in:
@@ -118,10 +118,9 @@ class PostQueryBuilder
|
||||
relation = add_range_relation(q[:filesize], "posts.file_size", relation)
|
||||
relation = add_range_relation(q[:date], "posts.created_at", relation)
|
||||
relation = add_range_relation(q[:age], "posts.created_at", relation)
|
||||
relation = add_range_relation(q[:general_tag_count], "posts.tag_count_general", relation)
|
||||
relation = add_range_relation(q[:artist_tag_count], "posts.tag_count_artist", relation)
|
||||
relation = add_range_relation(q[:copyright_tag_count], "posts.tag_count_copyright", relation)
|
||||
relation = add_range_relation(q[:character_tag_count], "posts.tag_count_character", relation)
|
||||
TagCategory.categories.each do |category|
|
||||
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)
|
||||
|
||||
@@ -513,29 +512,11 @@ class PostQueryBuilder
|
||||
when "tagcount_asc"
|
||||
relation = relation.order("posts.tag_count ASC")
|
||||
|
||||
when "gentags", "gentags_desc"
|
||||
relation = relation.order("posts.tag_count_general DESC")
|
||||
when /(#{TagCategory.short_name_regex})tags(?:\Z|_desc)/
|
||||
relation = relation.order("posts.tag_count_#{TagCategory.short_name_mapping[$1]} DESC")
|
||||
|
||||
when "gentags_asc"
|
||||
relation = relation.order("posts.tag_count_general ASC")
|
||||
|
||||
when "arttags", "arttags_desc"
|
||||
relation = relation.order("posts.tag_count_artist DESC")
|
||||
|
||||
when "arttags_asc"
|
||||
relation = relation.order("posts.tag_count_artist ASC")
|
||||
|
||||
when "chartags", "chartags_desc"
|
||||
relation = relation.order("posts.tag_count_character DESC")
|
||||
|
||||
when "chartags_asc"
|
||||
relation = relation.order("posts.tag_count_character ASC")
|
||||
|
||||
when "copytags", "copytags_desc"
|
||||
relation = relation.order("posts.tag_count_copyright DESC")
|
||||
|
||||
when "copytags_asc"
|
||||
relation = relation.order("posts.tag_count_copyright ASC")
|
||||
when /(#{TagCategory.short_name_regex})tags_asc/
|
||||
relation = relation.order("posts.tag_count_#{TagCategory.short_name_mapping[$1]} ASC")
|
||||
|
||||
when "rank"
|
||||
relation = relation.order("log(3, posts.score) + (extract(epoch from posts.created_at) - extract(epoch from timestamp '2005-05-24')) / 35000 DESC")
|
||||
|
||||
78
app/logical/tag_category.rb
Normal file
78
app/logical/tag_category.rb
Normal file
@@ -0,0 +1,78 @@
|
||||
class TagCategory
|
||||
module Mappings
|
||||
# Returns a hash mapping various tag categories to a numerical value.
|
||||
def mapping
|
||||
@@mapping ||= Hash[
|
||||
Danbooru.config.full_tag_config_info.map {|k,v| v["extra"].map {|y| [y,v["category"]]}}
|
||||
.reduce([],:+)]
|
||||
.update(Hash[Danbooru.config.full_tag_config_info.map {|k,v| [v["short"],v["category"]]}])
|
||||
.update( Hash[Danbooru.config.full_tag_config_info.map {|k,v| [k,v["category"]]}])
|
||||
end
|
||||
|
||||
# Returns a hash mapping more suited for views
|
||||
def canonical_mapping
|
||||
@@canonical_mapping ||= Hash[Danbooru.config.full_tag_config_info.map {|k,v| [k.capitalize,v["category"]]}]
|
||||
end
|
||||
|
||||
# Returns a hash mapping numerical category values to their string equivalent.
|
||||
def reverse_mapping
|
||||
@@reverse_mapping ||= Hash[Danbooru.config.full_tag_config_info.map {|k,v| [v["category"],k]}]
|
||||
end
|
||||
|
||||
# Returns a hash mapping for the short name usage in metatags
|
||||
def short_name_mapping
|
||||
@@short_name_mapping ||= Hash[Danbooru.config.full_tag_config_info.map {|k,v| [v["short"],k]}]
|
||||
end
|
||||
|
||||
# Returns a hash mapping for humanized_essential_tag_string (models/post.rb)
|
||||
def humanized_mapping
|
||||
@@humanized_mapping ||= Hash[Danbooru.config.full_tag_config_info.map {|k,v| [k,v["humanized"]]}]
|
||||
end
|
||||
|
||||
# Returns a hash mapping for humanized_essential_tag_string (models/post.rb)
|
||||
def header_mapping
|
||||
@@header_mapping ||= Hash[Danbooru.config.full_tag_config_info.map {|k,v| [k,v["header"]]}]
|
||||
end
|
||||
|
||||
# Returns a hash mapping for related tag buttons (javascripts/related_tag.js)
|
||||
def related_button_mapping
|
||||
@@related_button_mapping ||= Hash[Danbooru.config.full_tag_config_info.map {|k,v| [k,v["relatedbutton"]]}]
|
||||
end
|
||||
end
|
||||
|
||||
module Lists
|
||||
def categories
|
||||
@@categories ||= Danbooru.config.full_tag_config_info.keys
|
||||
end
|
||||
|
||||
def short_name_list
|
||||
@@short_name_list ||= short_name_mapping.keys
|
||||
end
|
||||
|
||||
def humanized_list
|
||||
Danbooru.config.humanized_tag_category_list
|
||||
end
|
||||
|
||||
def split_header_list
|
||||
Danbooru.config.split_tag_header_list
|
||||
end
|
||||
|
||||
def categorized_list
|
||||
Danbooru.config.categorized_tag_list
|
||||
end
|
||||
|
||||
def related_button_list
|
||||
Danbooru.config.related_tag_button_list
|
||||
end
|
||||
end
|
||||
|
||||
module Regexes
|
||||
def short_name_regex
|
||||
@@short_name_regex ||= short_name_list.join("|")
|
||||
end
|
||||
end
|
||||
|
||||
extend Mappings
|
||||
extend Lists
|
||||
extend Regexes
|
||||
end
|
||||
Reference in New Issue
Block a user