refactored post search

This commit is contained in:
albert
2012-01-27 13:05:41 -05:00
parent 8b241138cd
commit 75d977ae80
6 changed files with 29 additions and 20 deletions

View File

@@ -43,7 +43,7 @@ class Post < ActiveRecord::Base
scope :for_user, lambda {|user_id| where(["uploader_id = ?", user_id])}
scope :available_for_moderation, lambda {|hidden| hidden.present? ? where(["id IN (SELECT pd.post_id FROM post_disapprovals pd WHERE pd.user_id = ?)", CurrentUser.id]) : where(["id NOT IN (SELECT pd.post_id FROM post_disapprovals pd WHERE pd.user_id = ?)", CurrentUser.id])}
scope :hidden_from_moderation, lambda {where(["id IN (SELECT pd.post_id FROM post_disapprovals pd WHERE pd.user_id = ?)", CurrentUser.id])}
scope :tag_match, lambda {|query| Post.tag_match_helper(query)}
scope :tag_match, lambda {|query| PostQueryBuilder.new(query).build}
scope :positive, where("score > 1")
scope :negative, where("score < -1")
search_methods :tag_match
@@ -568,13 +568,6 @@ class Post < ActiveRecord::Base
end
end
module SearchMethods
def tag_match_helper(q)
builder = PostQueryBuilder.new(q)
builder.build
end
end
module UploaderMethods
def initialize_uploader
if uploader_id.blank?
@@ -904,7 +897,6 @@ class Post < ActiveRecord::Base
include FavoriteMethods
include UploaderMethods
include PoolMethods
extend SearchMethods
include VoteMethods
extend CountMethods
include CacheMethods

View File

@@ -211,7 +211,7 @@ class Tag < ActiveRecord::Base
:include => [],
:exclude => []
}
scan_query(query).each do |token|
if token =~ /\A(-uploader|uploader|-approver|approver|-pool|pool|-fav|fav|sub|md5|-rating|rating|width|height|mpixels|score|filesize|source|id|date|order|status|tagcount|gentags|arttags|chartags|copytags|parent):(.+)\Z/
case $1
@@ -308,7 +308,7 @@ class Tag < ActiveRecord::Base
parse_tag(token, q[:tags])
end
end
normalize_tags_in_query(q)
return q

View File

@@ -26,6 +26,7 @@ class TagAlias < ActiveRecord::Base
def process!
update_column(:status, "processing")
update_posts
clear_all_cache
update_column(:status, "active")
rescue Exception => e
update_column(:status, "error: #{e}")