added notes
This commit is contained in:
@@ -1,22 +1,23 @@
|
||||
class RelatedTagCalculator
|
||||
def find_tags(tag, limit)
|
||||
ActiveRecord::Base.connection.select_values_sql("SELECT tag_string FROM posts WHERE tag_index @@ to_tsquery('danbooru', ?) ORDER BY id DESC LIMIT ?", tag, limit)
|
||||
ActiveRecord::Base.select_values_sql("SELECT tag_string FROM posts WHERE tag_index @@ to_tsquery('danbooru', ?) ORDER BY id DESC LIMIT ?", tag, limit)
|
||||
end
|
||||
|
||||
def calculate_from_sample(name, limit, category_constraint = nil)
|
||||
counts = Hash.new {|h, k| h[k] = 0}
|
||||
|
||||
find_tags(name, limit).each do |post|
|
||||
find_tags(name, limit).each do |tags|
|
||||
tag_array = Tag.scan_tags(tags)
|
||||
if category_constraint
|
||||
categories = Tag.categories_for(post.tag_array)
|
||||
categories = Tag.categories_for(tag_array)
|
||||
|
||||
post.tag_array.each do |tag|
|
||||
tag_array.each do |tag|
|
||||
if categories[tag] == category_constraint && tag != name
|
||||
counts[tag] += 1
|
||||
end
|
||||
end
|
||||
else
|
||||
post.tag_array.each do |tag|
|
||||
tag_array.each do |tag|
|
||||
if tag != name
|
||||
counts[tag] += 1
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user