added notes

This commit is contained in:
albert
2010-02-24 15:40:55 -05:00
parent 7bb935256b
commit 55700efeb1
17 changed files with 462 additions and 27 deletions

View File

@@ -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