From 677a66ca0deebaa001b7946c35d41e25ada0fc1f Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Thu, 14 Jan 2021 23:30:00 -0800 Subject: search: parse and embed a copy of ScholarDoc object in results Maybe should refactor this to simply replace the object? Hrm. --- fatcat_scholar/search.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'fatcat_scholar/search.py') diff --git a/fatcat_scholar/search.py b/fatcat_scholar/search.py index d3cca80..e586bee 100644 --- a/fatcat_scholar/search.py +++ b/fatcat_scholar/search.py @@ -18,6 +18,7 @@ from pydantic import BaseModel from fatcat_scholar.config import settings from fatcat_scholar.identifiers import * +from fatcat_scholar.schema import ScholarDoc # i18n note: the use of gettext below doesn't actually do the translation here, # it just ensures that the strings are caught by babel for translation later @@ -129,7 +130,11 @@ def transform_es_results(resp: Response) -> List[dict]: # ensure collapse_key is a single value, not an array if type(h["collapse_key"]) == list: h["collapse_key"] = h["collapse_key"][0] - + # add ScholarDoc object as a helper (eg, to call python helpers) + try: + h["_obj"] = ScholarDoc.parse_obj(h) + except: + pass return results -- cgit v1.2.3