Commit 68e68257 authored by Georg Huhs's avatar Georg Huhs
Browse files

Make ordering code more flexible

parent eeb3e2bd
......@@ -513,10 +513,19 @@ def get_author(material_id, calc_id, author_id):
@http_auth.login_required
def get_suggestions():
suggestion_properties = ['material_name', 'structure_type', 'space_group_number', 'code_name']
# define sorting order,
# default is document count descending
# different ones for particular properties can be defined here
default_order = {'_count': 'desc'}
properties_orders = {
'material_name': {"_key": "asc"}
}
property = request.args.get('property')
if property not in suggestion_properties:
return {"message": "Quantity not provided or not available."}, 400
order = properties_orders.get(property, default_order)
search_results = es.search(index=es_config['index'], doc_type='material', body={
"size": 1,
"aggs": {
......@@ -524,7 +533,7 @@ def get_suggestions():
"terms": {
"field": property,
"size": 10000,
"order": {"_key": "asc"}
"order": order
}
}
}
......
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