server/search: prefer arrays over ranges
(No, it doesn't work recursively.) Also fix tests.
This commit is contained in:
parent
1e65622daf
commit
560a7d6839
2 changed files with 20 additions and 4 deletions
|
@ -4,14 +4,14 @@ from szurubooru.search import criteria, tokens
|
||||||
|
|
||||||
|
|
||||||
def _create_criterion(original_value, value):
|
def _create_criterion(original_value, value):
|
||||||
|
if ',' in value:
|
||||||
|
return criteria.ArrayCriterion(
|
||||||
|
original_value, value.split(','))
|
||||||
if '..' in value:
|
if '..' in value:
|
||||||
low, high = value.split('..', 1)
|
low, high = value.split('..', 1)
|
||||||
if not low and not high:
|
if not low and not high:
|
||||||
raise errors.SearchError('Empty ranged value')
|
raise errors.SearchError('Empty ranged value')
|
||||||
return criteria.RangedCriterion(original_value, low, high)
|
return criteria.RangedCriterion(original_value, low, high)
|
||||||
if ',' in value:
|
|
||||||
return criteria.ArrayCriterion(
|
|
||||||
original_value, value.split(','))
|
|
||||||
return criteria.PlainCriterion(original_value, value)
|
return criteria.PlainCriterion(original_value, value)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -84,6 +84,23 @@ def test_filter_by_name(
|
||||||
verify_unpaged(input, expected_user_names)
|
verify_unpaged(input, expected_user_names)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('input,expected_user_names', [
|
||||||
|
('name:u1', ['u1']),
|
||||||
|
('name:u2..', ['u2..']),
|
||||||
|
('name:u2*', ['u2..']),
|
||||||
|
('name:*..*', ['u2..', 'u3..x']),
|
||||||
|
('name:u3..x', ['u3..x']),
|
||||||
|
('name:*..x', ['u3..x']),
|
||||||
|
('name:u1,u3..x', ['u1', 'u3..x']),
|
||||||
|
])
|
||||||
|
def test_filter_by_name_that_looks_like_range(
|
||||||
|
verify_unpaged, input, expected_user_names, user_factory):
|
||||||
|
db.session.add(user_factory(name='u1'))
|
||||||
|
db.session.add(user_factory(name='u2..'))
|
||||||
|
db.session.add(user_factory(name='u3..x'))
|
||||||
|
db.session.flush()
|
||||||
|
verify_unpaged(input, expected_user_names)
|
||||||
|
|
||||||
@pytest.mark.parametrize('input,expected_user_names', [
|
@pytest.mark.parametrize('input,expected_user_names', [
|
||||||
('', ['u1', 'u2']),
|
('', ['u1', 'u2']),
|
||||||
('u1', ['u1']),
|
('u1', ['u1']),
|
||||||
|
@ -224,7 +241,6 @@ def test_random_sort(executor, user_factory):
|
||||||
('creation-date:bad..', errors.ValidationError),
|
('creation-date:bad..', errors.ValidationError),
|
||||||
('creation-date:..bad', errors.ValidationError),
|
('creation-date:..bad', errors.ValidationError),
|
||||||
('creation-date:bad..bad', errors.ValidationError),
|
('creation-date:bad..bad', errors.ValidationError),
|
||||||
('name:a..b', errors.SearchError),
|
|
||||||
('sort:', errors.SearchError),
|
('sort:', errors.SearchError),
|
||||||
('sort:nam', errors.SearchError),
|
('sort:nam', errors.SearchError),
|
||||||
('sort:name,as', errors.SearchError),
|
('sort:name,as', errors.SearchError),
|
||||||
|
|
Loading…
Reference in a new issue