From f5afbed2e5364befd4ff91d678bb443f25af0765 Mon Sep 17 00:00:00 2001 From: Daoud Clarke Date: Fri, 25 Feb 2022 22:11:09 +0000 Subject: [PATCH] Handle empty list --- mwmbl/tinysearchengine/rank.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mwmbl/tinysearchengine/rank.py b/mwmbl/tinysearchengine/rank.py index dbf692a..dae1dc9 100644 --- a/mwmbl/tinysearchengine/rank.py +++ b/mwmbl/tinysearchengine/rank.py @@ -55,6 +55,9 @@ def _score_result(terms, result: Document, is_complete: bool, max_score: float): def _order_results(terms: list[str], results: list[Document], is_complete: bool): + if len(results) == 0: + return [] + max_score = max(result.score for result in results) results_and_scores = [(_score_result(terms, result, is_complete, max_score), result) for result in results] ordered_results = sorted(results_and_scores, key=itemgetter(0), reverse=True)