aboutsummaryrefslogtreecommitdiff
path: root/server/szurubooru/func/similar.py
diff options
context:
space:
mode:
Diffstat (limited to 'server/szurubooru/func/similar.py')
-rw-r--r--server/szurubooru/func/similar.py8
1 files changed, 6 insertions, 2 deletions
diff --git a/server/szurubooru/func/similar.py b/server/szurubooru/func/similar.py
index 3955c03..8247de8 100644
--- a/server/szurubooru/func/similar.py
+++ b/server/szurubooru/func/similar.py
@@ -6,16 +6,20 @@ from szurubooru import model, search
_search_executor_config = search.configs.PostSearchConfig()
_search_executor = search.Executor(_search_executor_config)
+_max_removals = 3
+
def find_similar_posts(source_post: model.Post, limit: int) -> List[model.Post]:
results = []
queue = Queue() # contains lists of tags to search
queue.put(source_post.tags)
+ source_tag_count = len(source_post.tags)
while not queue.empty():
# put follow-up searches on the queue
last_tags = queue.get()
- if len(last_tags) > 1:
+ tag_count = len(last_tags)
+ if tag_count > 1 and tag_count > source_tag_count - _max_removals:
for removed_tag in last_tags:
next_search = list(filter(lambda t: t != removed_tag, last_tags))
queue.put(next_search)
@@ -27,7 +31,7 @@ def find_similar_posts(source_post: model.Post, limit: int) -> List[model.Post]:
query += ' -id:%d' % r.post_id
# execute
- _, posts = _search_executor.execute(query, 0, limit)
+ _, posts = _search_executor.execute(query, 0, limit - len(results))
# update results
for p in posts:

© 2015 - 2026 Jakob L. Kreuze