add pixiv id search

This commit is contained in:
albert
2013-03-31 14:43:54 -04:00
parent fc32a0023c
commit e2c2a8309d
7 changed files with 55 additions and 15 deletions

View File

@@ -124,7 +124,7 @@ class PostQueryBuilder
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)
relation = add_range_relation(q[:post_tag_count], "posts.tag_count", relation)
# relation = add_range_relation(q[:pixiv_id], "substring(posts.source, 'pixiv.net/img.*/([0-9]+)[^/]*$')::integer", relation)
relation = add_range_relation(q[:pixiv_id], "posts.pixiv_id", relation)
if q[:md5]
relation = relation.where(["posts.md5 IN (?)", q[:md5]])

View File

@@ -15,6 +15,7 @@ class Post < ActiveRecord::Base
before_save :update_tag_post_counts
before_save :set_tag_counts
before_validation :initialize_uploader, :on => :create
before_validation :parse_pixiv_id
belongs_to :updater, :class_name => "User"
belongs_to :approver, :class_name => "User"
belongs_to :uploader, :class_name => "User"
@@ -1011,7 +1012,21 @@ class Post < ActiveRecord::Base
q
end
end
module PixivMethods
def parse_pixiv_id
if source =~ %r!http://i\d\.pixiv\.net/img-inf/img/\d+/\d+/\d+/\d+/\d+/\d+/(\d+)_s.jpg!
self.pixiv_id = $1
elsif source =~ %r!http://i\d\.pixiv\.net/img\d+/img/[^\/]+/(\d+)!
self.pixiv_id = $1
elsif source =~ /pixiv\.net/ && source =~ /illust_id=(\d+)/
self.pixiv_id = $1
else
self.pixiv_id = nil
end
end
end
include FileMethods
include ImageMethods
include ApprovalMethods
@@ -1029,6 +1044,7 @@ class Post < ActiveRecord::Base
include NoteMethods
include ApiMethods
extend SearchMethods
include PixivMethods
def reload(options = nil)
super

View File

@@ -1,5 +1,5 @@
class Tag < ActiveRecord::Base
METATAGS = "-user|user|-approver|approver|commenter|comm|noter|-pool|pool|-fav|fav|sub|md5|-rating|rating|-locked|locked|width|height|mpixels|score|filesize|source|id|date|order|-status|status|tagcount|gentags|arttags|chartags|copytags|parent|pixiv"
METATAGS = "-user|user|-approver|approver|commenter|comm|noter|-pool|pool|-fav|fav|sub|md5|-rating|rating|-locked|locked|width|height|mpixels|score|filesize|source|id|date|order|-status|status|tagcount|gentags|arttags|chartags|copytags|parent|pixiv_id"
attr_accessible :category
has_one :wiki_page, :foreign_key => "name", :primary_key => "title"
@@ -370,8 +370,8 @@ class Tag < ActiveRecord::Base
when "status"
q[:status] = $2.downcase
when "pixiv"
q[:pixiv] = parse_helper($2)
when "pixiv_id"
q[:pixiv_id] = parse_helper($2)
end