From 23de3297bbd74980a2f6da326acc5da63ddef2fe Mon Sep 17 00:00:00 2001 From: Elena ``of Valhalla'' Grandi Date: Wed, 3 Feb 2021 11:24:46 +0100 Subject: Add a default_sort option to collections --- .../complex/items/0b33e2b72add4ccab93a8cb7e2014b10.yaml | 1 + .../complex/items/5084bc6e94f24dc6976629282ef30419.yaml | 1 + .../complex/items/5be0a92b6ad745fc9ffced106c94d221.yaml | 1 + .../complex/items/8e9fa1ed3c1b4a30a6be7a98eda0cfa7.yaml | 1 + .../complex/items/b4b1feb620aa46f5b6784fbc608e4cd8.yaml | 1 + tests/data/complex/settings.yaml | 6 ++++++ tests/test_collection.py | 16 ++++++++++++++-- 7 files changed, 25 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/data/complex/items/0b33e2b72add4ccab93a8cb7e2014b10.yaml b/tests/data/complex/items/0b33e2b72add4ccab93a8cb7e2014b10.yaml index c9aece7..6fd18e1 100644 --- a/tests/data/complex/items/0b33e2b72add4ccab93a8cb7e2014b10.yaml +++ b/tests/data/complex/items/0b33e2b72add4ccab93a8cb7e2014b10.yaml @@ -8,3 +8,4 @@ keywords: [] exists: with_default: default value amount: 2 +order: charlie diff --git a/tests/data/complex/items/5084bc6e94f24dc6976629282ef30419.yaml b/tests/data/complex/items/5084bc6e94f24dc6976629282ef30419.yaml index 874833e..6abdd6d 100644 --- a/tests/data/complex/items/5084bc6e94f24dc6976629282ef30419.yaml +++ b/tests/data/complex/items/5084bc6e94f24dc6976629282ef30419.yaml @@ -12,4 +12,5 @@ keywords: [] exists: true with_default: default value amount: 1 +order: delta # and a comment at the end diff --git a/tests/data/complex/items/5be0a92b6ad745fc9ffced106c94d221.yaml b/tests/data/complex/items/5be0a92b6ad745fc9ffced106c94d221.yaml index c57b5f0..18ff2c9 100644 --- a/tests/data/complex/items/5be0a92b6ad745fc9ffced106c94d221.yaml +++ b/tests/data/complex/items/5be0a92b6ad745fc9ffced106c94d221.yaml @@ -8,3 +8,4 @@ keywords: [] exists: with_default: default value amount: 10 +order: alpha diff --git a/tests/data/complex/items/8e9fa1ed3c1b4a30a6be7a98eda0cfa7.yaml b/tests/data/complex/items/8e9fa1ed3c1b4a30a6be7a98eda0cfa7.yaml index e23a563..da82d8d 100644 --- a/tests/data/complex/items/8e9fa1ed3c1b4a30a6be7a98eda0cfa7.yaml +++ b/tests/data/complex/items/8e9fa1ed3c1b4a30a6be7a98eda0cfa7.yaml @@ -10,3 +10,4 @@ keywords: [] exists: with_default: 'default value' amount: 0 +order: diff --git a/tests/data/complex/items/b4b1feb620aa46f5b6784fbc608e4cd8.yaml b/tests/data/complex/items/b4b1feb620aa46f5b6784fbc608e4cd8.yaml index 50c57e2..6661167 100644 --- a/tests/data/complex/items/b4b1feb620aa46f5b6784fbc608e4cd8.yaml +++ b/tests/data/complex/items/b4b1feb620aa46f5b6784fbc608e4cd8.yaml @@ -8,3 +8,4 @@ keywords: [] exists: with_default: default value amount: 20 +order: zucchini diff --git a/tests/data/complex/settings.yaml b/tests/data/complex/settings.yaml index e6781b5..1fd36b5 100644 --- a/tests/data/complex/settings.yaml +++ b/tests/data/complex/settings.yaml @@ -1,6 +1,8 @@ name: "Fully featured lesana collection" lang: 'english' entry_label: '{{ eid }}: {{ name }} ({{ tags }})' +default_sort: + - order fields: - name: name type: string @@ -33,3 +35,7 @@ fields: type: integer index: field sortable: true + - name: order + type: string + index: field + sortable: true diff --git a/tests/test_collection.py b/tests/test_collection.py index 6a6e5e3..4c95c2b 100644 --- a/tests/test_collection.py +++ b/tests/test_collection.py @@ -289,9 +289,9 @@ class testComplexCollection(unittest.TestCase): self.collection.settings['name'], "Fully featured lesana collection", ) - self.assertEqual(len(self.collection.settings['fields']), 9) + self.assertEqual(len(self.collection.settings['fields']), 10) self.assertIsNotNone(self.collection.stemmer) - self.assertEqual(len(self.collection.indexed_fields), 7) + self.assertEqual(len(self.collection.indexed_fields), 8) def test_index(self): indexed = self.collection.update_cache() @@ -379,6 +379,18 @@ class testComplexCollection(unittest.TestCase): self.assertEqual(matches[2].data['amount'], 10) self.assertEqual(matches[3].data['amount'], 2) + def test_default_sorted_search(self): + # search in ascending order + self.collection.start_search('Amount') + res = self.collection.get_search_results() + matches = list(res) + self.assertEqual(len(matches), 4) + print([m.data['order'] for m in matches]) + self.assertEqual(matches[0].data['order'], None) + self.assertEqual(matches[1].data['order'], 'alpha') + self.assertEqual(matches[2].data['order'], 'charlie') + self.assertEqual(matches[3].data['order'], 'zucchini') + class testCollectionWithErrors(unittest.TestCase): def setUp(self): -- cgit v1.2.3