Skip to content

Commit 64be307

Browse files
committed
fix: sorting keys need to follow order
1 parent d6e22b9 commit 64be307

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

cumulus_lambda_functions/uds_api/dapa/granules_dapa_query_es.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -39,27 +39,27 @@ def get_sorting_arguments(self):
3939
{'properties.datetime': {'order': 'desc'}},
4040
{'id': {'order': 'asc'}}
4141
]
42-
sorting_dict = {}
4342
sort_keys = [k.strip() for k in self.__sort_by.split(',')]
43+
sort_key_set = set()
44+
sort_keys_dsl = []
4445
for each_key in sort_keys:
4546
if each_key.startswith('+'):
46-
sorting_dict[each_key[1:]] = {'order': 'asc'}
47+
current_sort_key = each_key[1:]
48+
current_sort_dict = {current_sort_key: {'order': 'asc'}}
4749
elif each_key.startswith('-'):
48-
sorting_dict[each_key[1:]] = {'order': 'desc'}
50+
current_sort_key = each_key[1:]
51+
current_sort_dict = {current_sort_key: {'order': 'desc'}}
4952
else:
50-
sorting_dict[each_key] = {'order': 'asc'}
51-
if 'properties.datetime' not in sorting_dict:
52-
sorting_dict['properties.datetime'] = {'order': 'desc'}
53-
if 'id' not in sorting_dict:
54-
sorting_dict['id'] = {'order': 'asc'}
55-
56-
sorting_array = [
57-
{'properties.datetime': sorting_dict.pop('properties.datetime')},
58-
{'id': sorting_dict.pop('id')},
59-
]
60-
for k, v in sorting_dict.items():
61-
sorting_array.append({k: v})
62-
return sorting_array
53+
current_sort_key = each_key
54+
current_sort_dict = {current_sort_key: {'order': 'asc'}}
55+
if current_sort_key not in sort_key_set:
56+
sort_keys_dsl.append(current_sort_dict)
57+
sort_key_set.add(current_sort_key)
58+
if 'properties.datetime' not in sort_key_set:
59+
sort_keys_dsl.append({'properties.datetime': {'order': 'desc'}})
60+
if 'id' not in sort_key_set:
61+
sort_keys_dsl.append({'id': {'order': 'asc'}})
62+
return sort_keys_dsl
6363

6464
def __generate_es_dsl(self):
6565
query_terms = []

0 commit comments

Comments
 (0)