From db921edb6e63c8c5bd25f03beea7a4c08bf0996c Mon Sep 17 00:00:00 2001 From: Martin Czygan Date: Wed, 23 Dec 2020 03:48:15 +0100 Subject: [testing] use api for id lookups --- fuzzycat/matching.py | 41 +++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/fuzzycat/matching.py b/fuzzycat/matching.py index 4573053..413665a 100644 --- a/fuzzycat/matching.py +++ b/fuzzycat/matching.py @@ -38,33 +38,34 @@ def match_release_fuzzy( es = elasticsearch.Elasticsearch([es]) if es is None: es = elasticsearch.Elasticsearch() + if api is None: + api = public_api(FATCAT_API_URL) # Try to match by external identifier. # TODO: use api, ability to disable; benchmark ext_ids = release.ext_ids - attrs = { - "doi": "doi", - "wikidata_qid": "wikidata_qid", - "isbn13": "isbn13", - "pmid": "pmid", - "pmcid": "pmcid", - "core": "code_id", - "arxiv": "arxiv_id", - "jstor": "jstor_id", - "ark": "ark_id", - "mag": "mag_id", - } - for attr, es_field in attrs.items(): + attrs = ( + "doi", + "wikidata_qid", + "isbn13", + "pmid", + "pmcid", + "core", + "arxiv", + "jstor", + "ark", + "mag", + "doaj", + "dblp", + "oai", + ) + for attr in attrs: value = getattr(ext_ids, attr) if not value: continue - s = (elasticsearch_dsl.Search(using=es, - index="fatcat_release").query("term", **{ - es_field: value - }).extra(size=size)) - resp = s.execute() - if len(resp) > 0: - return response_to_entity_list(resp, entity_type=ReleaseEntity, api=api) + r = api.lookup_release(**{attr: value}) + if r: + return r body = { "query": { -- cgit v1.2.3