From 6b68c77e177c79360af09fe737ebad147d8dd416 Mon Sep 17 00:00:00 2001 From: rr- Date: Mon, 13 Jun 2016 20:08:39 +0200 Subject: [PATCH] server/posts: add relation-count token --- API.md | 2 ++ client/html/help_search_posts.tpl | 8 ++++++++ server/szurubooru/db/post.py | 5 +++++ server/szurubooru/search/configs/post_search_config.py | 2 ++ 4 files changed, 17 insertions(+) diff --git a/API.md b/API.md index 2f9e0a9..529e25d 100644 --- a/API.md +++ b/API.md @@ -593,6 +593,7 @@ data. | `comment-count` | having given number of comments | | `fav-count` | favorited by given number of users | | `note-count` | having given number of annotations | + | `relation-count` | having given number of relations | | `feature-count` | having been featured given number of times | | `type` | given type of posts. `` can be either `image`, `animation` (or `animated` or `anim`), `flash` (or `swf`) or `video` (or `webm`). | | `file-size` | having given file size (in bytes) | @@ -630,6 +631,7 @@ data. | `comment-count` | most commented first | | `fav-count` | loved by most | | `note-count` | with most annotations | + | `relation-count` | with most relations | | `feature-count` | most often featured | | `file-size` | largest files first | | `image-width` | widest images first | diff --git a/client/html/help_search_posts.tpl b/client/html/help_search_posts.tpl index 52e59d1..ed2d523 100644 --- a/client/html/help_search_posts.tpl +++ b/client/html/help_search_posts.tpl @@ -54,6 +54,10 @@ note-count having given number of annotations + + relation-count + having given number of relations + feature-count having been featured given number of times @@ -189,6 +193,10 @@ note-count with most annotations + + relation-count + with most relations + feature-count most often featured diff --git a/server/szurubooru/db/post.py b/server/szurubooru/db/post.py index e413e23..4a12899 100644 --- a/server/szurubooru/db/post.py +++ b/server/szurubooru/db/post.py @@ -187,3 +187,8 @@ class Post(Base): select([func.count(PostNote.post_id)]) \ .where(PostNote.post_id == post_id) \ .correlate_except(PostNote)) + + relation_count = column_property( + select([func.count(PostRelation.child_id)]) \ + .where(PostRelation.parent_id == post_id) \ + .correlate_except(PostRelation)) diff --git a/server/szurubooru/search/configs/post_search_config.py b/server/szurubooru/search/configs/post_search_config.py index 1039cf6..4e4f69b 100644 --- a/server/szurubooru/search/configs/post_search_config.py +++ b/server/szurubooru/search/configs/post_search_config.py @@ -153,6 +153,7 @@ class PostSearchConfig(BaseSearchConfig): 'comment-count': search_util.create_num_filter(db.Post.comment_count), 'fav-count': search_util.create_num_filter(db.Post.favorite_count), 'note-count': search_util.create_num_filter(db.Post.note_count), + 'relation-count': search_util.create_num_filter(db.Post.relation_count), 'feature-count': search_util.create_num_filter(db.Post.feature_count), 'type': search_util.create_str_filter(db.Post.type, _type_transformer), 'file-size': search_util.create_num_filter(db.Post.file_size), @@ -186,6 +187,7 @@ class PostSearchConfig(BaseSearchConfig): 'comment-count': (db.Post.comment_count, self.SORT_DESC), 'fav-count': (db.Post.favorite_count, self.SORT_DESC), 'note-count': (db.Post.note_count, self.SORT_DESC), + 'relation-count': (db.Post.relation_count, self.SORT_DESC), 'feature-count': (db.Post.feature_count, self.SORT_DESC), 'file-size': (db.Post.file_size, self.SORT_DESC), ('image-width', 'width'): (db.Post.canvas_width, self.SORT_DESC),