Skip to content

Commit

Permalink
Preserve sort order
Browse files Browse the repository at this point in the history
  • Loading branch information
scheb committed Mar 8, 2024
1 parent dd95170 commit 2e554be
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions recipe_db/search/elasticsearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ def __init__(self, result: ObjectApiResponse):

@property
def recipes(self) -> Iterable[Recipe]:
# TODO: preserve score
ids = map(lambda r: r['_id'], self._result)
recipes = Recipe.objects.filter(uid__in=ids)
ids = list(map(lambda r: r['_id'], self._result))
builder = RecipeResultBuilder()
recipes = list(Recipe.objects.filter(uid__in=ids))
recipes = sorted(recipes, key=lambda r: ids.index(r.uid))
for recipe in recipes:
yield builder.create_recipe_result(recipe)

Expand Down

0 comments on commit 2e554be

Please sign in to comment.