From 172b956e483e3553070fc8b930fff90b1e28a297 Mon Sep 17 00:00:00 2001 From: rr- Date: Wed, 11 May 2016 22:07:52 +0200 Subject: [PATCH] server/search: permit search for tags by alias --- server/szurubooru/search/base_search_config.py | 2 +- server/szurubooru/search/tag_search_config.py | 12 ++++++++++-- .../tests/search/test_tag_search_config.py | 1 + 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/server/szurubooru/search/base_search_config.py b/server/szurubooru/search/base_search_config.py index 9f97973..f07f204 100644 --- a/server/szurubooru/search/base_search_config.py +++ b/server/szurubooru/search/base_search_config.py @@ -134,5 +134,5 @@ class BaseSearchConfig(object): subquery = subquery.options(sqlalchemy.orm.lazyload('*')) subquery = filter_func(subquery, criterion) subquery = subquery.subquery('t') - return query.filter(left_id_column == subquery.c.foreign_id) + return query.filter(left_id_column.in_(subquery)) return func diff --git a/server/szurubooru/search/tag_search_config.py b/server/szurubooru/search/tag_search_config.py index bea17f2..689bba7 100644 --- a/server/szurubooru/search/tag_search_config.py +++ b/server/szurubooru/search/tag_search_config.py @@ -23,12 +23,20 @@ class TagSearchConfig(BaseSearchConfig): @property def anonymous_filter(self): - return self._create_str_filter(db.Tag.first_name) + return self._create_subquery_filter( + db.Tag.tag_id, + db.TagName.tag_id, + db.TagName.name, + self._create_str_filter) @property def named_filters(self): return util.unalias_dict({ - 'name': self._create_str_filter(db.Tag.first_name), + 'name': self._create_subquery_filter( + db.Tag.tag_id, + db.TagName.tag_id, + db.TagName.name, + self._create_str_filter), 'category': self._create_subquery_filter( db.Tag.category_id, db.TagCategory.tag_category_id, diff --git a/server/szurubooru/tests/search/test_tag_search_config.py b/server/szurubooru/tests/search/test_tag_search_config.py index 2e834fc..3b23433 100644 --- a/server/szurubooru/tests/search/test_tag_search_config.py +++ b/server/szurubooru/tests/search/test_tag_search_config.py @@ -47,6 +47,7 @@ def test_filter_anonymous(verify_unpaged, tag_factory, input, expected_tag_names ('name:tag1,tag2', ['tag1', 'tag2']), ('-name:tag1,tag3', ['tag2', 'tag4']), ('name:tag4', ['tag4']), + ('name:tag5', ['tag4']), ('name:tag4,tag5', ['tag4']), ]) def test_filter_by_name(verify_unpaged, tag_factory, input, expected_tag_names):