Fix sorting order by exact
@@ -158,6 +158,15 @@ class SearchAPI(APIView):
return JsonResponse({'message': '{}'.format('{}: query error. Contact a server administrator.'
.format(type(gen_ex)))}, status=520)
+ if sort == 'author':
+ sqs = sqs.order_by('author_exact')
+ elif sort == '-author':
+ sqs = sqs.order_by('-author_exact')
+ elif sort == 'title':
+ sqs = sqs.order_by('title_exact')
+ elif sort == '-title':
+ sqs = sqs.order_by('-title_exact')
+ else:
sqs = sqs.order_by(sort)
resources = []
@@ -267,15 +276,6 @@ class SearchAPI(APIView):
"geo": pt
})
- if sort == 'title':
- resources = sorted(resources, key=lambda idx: idx['title'].lower())
- elif sort == '-title':
- resources = sorted(resources, key=lambda idx: idx['title'].lower(), reverse=True)
- elif sort == 'author':
- resources = sorted(resources, key=lambda idx: idx['author'].lower())
- elif sort == '-author':
- resources = sorted(resources, key=lambda idx: idx['author'].lower(), reverse=True)
-
return JsonResponse({
'resources': json.dumps(resources),
'geodata': json.dumps(geodata),
