diff --git a/viecpro_typesense/collections.py b/viecpro_typesense/collections.py index f6f31c8..8f49cff 100644 --- a/viecpro_typesense/collections.py +++ b/viecpro_typesense/collections.py @@ -26,7 +26,7 @@ class Config: "bibtex", handler=BibtexShortTitleHandler, options=O(facet=True, optional=True)) kind = StringField("bibtex", handler=BibtexTypeHandler, options=O(facet=True, optional=True)) - tag = StringField("url", handler=ZoteroTagHandler, + tag = StringField("bibs_url", handler=ZoteroTagHandler, options=O(facet=True, optional=False)) related_doc = RelatedReferenceDocField( ("content_type", "object_id"), options=O(facet=True, optional=True)) diff --git a/viecpro_typesense/handlers.py b/viecpro_typesense/handlers.py index 7a15ac7..53ef11e 100644 --- a/viecpro_typesense/handlers.py +++ b/viecpro_typesense/handlers.py @@ -21,6 +21,8 @@ "start_date": el.start_date_written.split("<")[0] if el.start_date_written else "", "end_date": el.end_date_written.split("<")[0] if el.end_date_written else "", }) for el in PersonInstitution.objects.filter(relation_type__name="hatte den Hofstaat")] +zotero_cache = {} + def fixstring(string): if isinstance(string, str): @@ -155,15 +157,19 @@ def func(bibtex): return bib.get("type", "") class ZoteroTagHandler(Handler): - def func(zotero_url): + def func(zotero_url): + if zotero_url in zotero_cache: + return zotero_cache[zotero_url] json = requests.get( zotero_url, params={"key": os.environ.get("ZOTERO_API_KEY")} ).json() - tags = json["data"].get("tags") + tags = json["data"].get("tags", []) tag_group = [tag["tag"][2:] for tag in tags if tag["tag"].startswith("1_")] if len(tag_group) == 1: + zotero_cache[zotero_url] = tag_group[0] return tag_group[0] else: + zotero_cache[zotero_url] = "Allgemein" return "Allgemein"