Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use attrgetter in sorted function #5936

Merged
merged 3 commits into from Jul 16, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion 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
Expand Down Expand Up @@ -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
Expand Down
5 changes: 0 additions & 5 deletions readthedocs/search/utils.py
Expand Up @@ -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.
Expand Down
5 changes: 3 additions & 2 deletions readthedocs/search/views.py
Expand Up @@ -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
Expand Down Expand Up @@ -129,8 +130,8 @@ 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)
)
dojutsu-user marked this conversation as resolved.
Show resolved Hide resolved

result.meta.inner_hits = sorted_results
except Exception:
Expand Down