aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Czygan <martin.czygan@gmail.com>2020-12-23 03:48:15 +0100
committerMartin Czygan <martin.czygan@gmail.com>2020-12-23 03:48:15 +0100
commitdb921edb6e63c8c5bd25f03beea7a4c08bf0996c (patch)
tree37ca39dcb6d223327737b119f129250ef4977b20
parent42415e0e7b272de9006123ea983a5b6bb8c5b4a7 (diff)
downloadfuzzycat-db921edb6e63c8c5bd25f03beea7a4c08bf0996c.tar.gz
fuzzycat-db921edb6e63c8c5bd25f03beea7a4c08bf0996c.zip
[testing] use api for id lookups
-rw-r--r--fuzzycat/matching.py41
1 files 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": {