diff --git a/readthedocs/search/api.py b/readthedocs/search/api.py index bc30ceb8a92..3ccd6d18190 100644 --- a/readthedocs/search/api.py +++ b/readthedocs/search/api.py @@ -1,5 +1,6 @@ import itertools import logging +from operator import attrgetter from pprint import pformat from rest_framework import generics, serializers @@ -54,7 +55,7 @@ def get_inner_hits(self, obj): '_source': hit._source.to_dict(), 'highlight': self._get_inner_hits_highlights(hit), } - for hit in sorted(all_results, key=utils._get_hit_score, reverse=True) + for hit in sorted(all_results, key=attrgetter('_score'), reverse=True) ] return sorted_results diff --git a/readthedocs/search/utils.py b/readthedocs/search/utils.py index 031e8578150..0ff42ddcdd2 100644 --- a/readthedocs/search/utils.py +++ b/readthedocs/search/utils.py @@ -161,11 +161,6 @@ def _indexing_helper(html_objs_qs, wipe=False): delete_objects_in_es.delay(**kwargs) -def _get_hit_score(res): - """Returns the _score of a single ES search result hits.""" - return res._score - - def _remove_newlines_from_dict(highlight): """ Recursively change results to turn newlines into periods. diff --git a/readthedocs/search/views.py b/readthedocs/search/views.py index 61f28c9a3d9..af5f97446ff 100644 --- a/readthedocs/search/views.py +++ b/readthedocs/search/views.py @@ -2,6 +2,7 @@ import collections import itertools import logging +from operator import attrgetter from pprint import pformat from django.shortcuts import get_object_or_404, render @@ -129,7 +130,7 @@ def elastic_search(request, project_slug=None): hit.highlight.to_dict() ), } - for hit in sorted(all_results, key=utils._get_hit_score, reverse=True) + for hit in sorted(all_results, key=attrgetter('_score'), reverse=True) ] result.meta.inner_hits = sorted_results