Commit 08e412bf by Dennis Jen Committed by Daniel Friedman

added review comments

parent 09c0c280
...@@ -269,7 +269,7 @@ class RosterEntry(DocType): ...@@ -269,7 +269,7 @@ class RosterEntry(DocType):
Raises `ValueError` if both `segments` and `ignore_segments` are provided. Raises `ValueError` if both `segments` and `ignore_segments` are provided.
""" """
if sort_policies is None or len(sort_policies) == 0: if not sort_policies:
sort_policies = [{ sort_policies = [{
'order_by': None, 'order_by': None,
'sort_order': None 'sort_order': None
...@@ -320,17 +320,16 @@ class RosterEntry(DocType): ...@@ -320,17 +320,16 @@ class RosterEntry(DocType):
search.query.must.append(Q('multi_match', query=text_search, fields=['name', 'username', 'email'])) search.query.must.append(Q('multi_match', query=text_search, fields=['name', 'username', 'email']))
# construct the sort hierarchy # construct the sort hierarchy
sort_terms = [] search = search.sort(*[
for sort_policy in sort_policies: {
sort_order = sort_policy['sort_order']
term = {
sort_policy['order_by']: { sort_policy['order_by']: {
'order': sort_order, 'order': sort_policy['sort_order'],
'missing': '_last' if sort_order == 'asc' else '_first', # ordering of missing fields # ordering of missing fields
'missing': '_last' if sort_policy['sort_order'] == 'asc' else '_first'
} }
} }
sort_terms.append(term) for sort_policy in sort_policies
search = search.sort(*sort_terms) ])
return search return search
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment