File tree Expand file tree Collapse file tree 3 files changed +4
-7
lines changed Expand file tree Collapse file tree 3 files changed +4
-7
lines changed Original file line number Diff line number Diff line change 1
1
import itertools
2
2
import logging
3
+ from operator import attrgetter
3
4
from pprint import pformat
4
5
5
6
from rest_framework import generics , serializers
@@ -54,7 +55,7 @@ def get_inner_hits(self, obj):
54
55
'_source' : hit ._source .to_dict (),
55
56
'highlight' : self ._get_inner_hits_highlights (hit ),
56
57
}
57
- for hit in sorted (all_results , key = utils . _get_hit_score , reverse = True )
58
+ for hit in sorted (all_results , key = attrgetter ( '_score' ) , reverse = True )
58
59
]
59
60
60
61
return sorted_results
Original file line number Diff line number Diff line change @@ -161,11 +161,6 @@ def _indexing_helper(html_objs_qs, wipe=False):
161
161
delete_objects_in_es .delay (** kwargs )
162
162
163
163
164
- def _get_hit_score (res ):
165
- """Returns the _score of a single ES search result hits."""
166
- return res ._score
167
-
168
-
169
164
def _remove_newlines_from_dict (highlight ):
170
165
"""
171
166
Recursively change results to turn newlines into periods.
Original file line number Diff line number Diff line change 2
2
import collections
3
3
import itertools
4
4
import logging
5
+ from operator import attrgetter
5
6
from pprint import pformat
6
7
7
8
from django .shortcuts import get_object_or_404 , render
@@ -129,7 +130,7 @@ def elastic_search(request, project_slug=None):
129
130
hit .highlight .to_dict ()
130
131
),
131
132
}
132
- for hit in sorted (all_results , key = utils . _get_hit_score , reverse = True )
133
+ for hit in sorted (all_results , key = attrgetter ( '_score' ) , reverse = True )
133
134
)
134
135
135
136
result .meta .inner_hits = sorted_results
You can’t perform that action at this time.
0 commit comments