added popular exploration, added order:rank

This commit is contained in:
albert
2011-08-11 15:39:51 -04:00
parent bd51079fc1
commit e42ea9c608
25 changed files with 296 additions and 61 deletions

View File

@@ -13,6 +13,7 @@ class Comment < ActiveRecord::Base
scope :body_matches, lambda {|query| where("body_index @@ plainto_tsquery(?)", query).order("comments.id DESC")}
scope :hidden, lambda {|user| where("score < ?", user.comment_threshold)}
scope :post_tag_match, lambda {|query| joins(:post).where("posts.tag_index @@ to_tsquery('danbooru', ?)", query)}
scope :for_user, lambda {|user_id| where("creator_id = ?", user_id)}
search_methods :body_matches, :post_tag_match

View File

@@ -1,4 +1,4 @@
class Favorite < ActiveRecord::Base
belongs_to :post
scope :for_user, lambda {|user_id| where("user_id = ?", user_id)}
scope :for_user, lambda {|user_id| where("user_id = #{user_id}")}
end

View File

@@ -8,6 +8,7 @@ class ForumPost < ActiveRecord::Base
validates_presence_of :body, :creator_id
validate :validate_topic_is_unlocked
scope :body_matches, lambda {|body| where(["text_index @@ plainto_tsquery(?)", body])}
scope :for_user, lambda {|user_id| where("creator_id = ?", user_id)}
search_methods :body_matches
def self.new_reply(params)

View File

@@ -1,6 +1,7 @@
class NoteVersion < ActiveRecord::Base
before_validation :initialize_updater
belongs_to :updater, :class_name => "User"
scope :for_user, lambda {|user_id| where("updater_id = ?", user_id)}
def initialize_updater
self.updater_id = CurrentUser.id

View File

@@ -5,6 +5,7 @@ class PoolVersion < ActiveRecord::Base
belongs_to :pool
belongs_to :updater, :class_name => "User"
before_validation :initialize_updater
scope :for_user, lambda {|user_id| where("updater_id = ?", user_id)}
def initialize_updater
self.updater_id = CurrentUser.id

View File

@@ -586,6 +586,10 @@ class Post < ActiveRecord::Base
relation = relation.where("posts.rating <> 'e'")
end
if q[:order] == "rank"
relation = relation.where("p.score > 0 and p.created_at >= ?", 0, 3.days.ago)
end
case q[:order]
when "id", "id_asc"
relation = relation.order("posts.id")
@@ -619,6 +623,9 @@ class Post < ActiveRecord::Base
when "filesize_asc"
relation = relation.order("posts.file_size")
when "rank"
sql << " ORDER BY log(3, p.score) + (extract(epoch from p.created_at) - extract(epoch from timestamp '2005-05-24')) / 45000 DESC"
else
relation = relation.order("posts.id DESC")
end

View File

@@ -2,6 +2,7 @@ class PostVersion < ActiveRecord::Base
belongs_to :post
belongs_to :updater, :class_name => "User"
before_validation :initialize_updater
scope :for_user, lambda {|user_id| where("updater_id = ?", user_id)}
def self.create_from_post(post)
if post.created_at == post.updated_at

View File

@@ -9,6 +9,7 @@ class UserFeedback < ActiveRecord::Base
scope :positive, where("category = ?", "positive")
scope :neutral, where("category = ?", "neutral")
scope :negative, where("category = ?", "negative")
scope :for_user, lambda {|user_id| where("user_id = ?", user_id)}
def initialize_creator
self.creator_id = CurrentUser.id

View File

@@ -1,6 +1,7 @@
class WikiPageVersion < ActiveRecord::Base
belongs_to :wiki_page
belongs_to :updater, :class_name => "User"
scope :for_user, lambda {|user_id| where("updater_id = ?", user_id)}
def updater_name
User.id_to_name(updater_id)