diff options
author | Bryan Newbold <bnewbold@archive.org> | 2020-09-17 23:14:22 -0700 |
---|---|---|
committer | Bryan Newbold <bnewbold@archive.org> | 2020-09-17 23:17:06 -0700 |
commit | 360726ab527ca736f3ff8359e8c6101926017e3e (patch) | |
tree | 6526d561a0c5fdad90ed311b69b809b0cc2fc57f /fatcat_scholar/search.py | |
parent | a7c76d1a835ab525be2f59dbd0d7ee487c0bd33c (diff) | |
download | fatcat-scholar-360726ab527ca736f3ff8359e8c6101926017e3e.tar.gz fatcat-scholar-360726ab527ca736f3ff8359e8c6101926017e3e.zip |
search: handle direct DOI and PMCID queries
If query is a single token which looks like a valid PMCID or DOI, with
no surrounding quotes, then expand scope and filter to that single
external identifier.
Diffstat (limited to 'fatcat_scholar/search.py')
-rw-r--r-- | fatcat_scholar/search.py | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/fatcat_scholar/search.py b/fatcat_scholar/search.py index 0b6798d..d29a720 100644 --- a/fatcat_scholar/search.py +++ b/fatcat_scholar/search.py @@ -16,6 +16,8 @@ from pydantic import BaseModel # pytype: enable=import-error +from fatcat_scholar.identifiers import * + # 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 @@ -97,15 +99,20 @@ def do_fulltext_search( search = Search(using=es_client, index=settings.ELASTICSEARCH_FULLTEXT_INDEX) - # Convert raw DOIs to DOI queries - if ( - query.q - and len(query.q.split()) == 1 - and query.q.startswith("10.") - and query.q.count("/") >= 1 - ): - search = search.filter("terms", doi=query.q) - query.q = "*" + # Try handling raw identifier queries + if query.q and len(query.q.strip().split()) == 1 and not '"' in query.q: + doi = clean_doi(query.q) + if doi: + query.q = f'doi:"{doi}"' + query.filter_type = "everything" + query.filter_availability = "everything" + query.filter_time = "all_time" + pmcid = clean_pmcid(query.q) + if pmcid: + query.q = f'pmcid:"{pmcid}"' + query.filter_type = "everything" + query.filter_availability = "everything" + query.filter_time = "all_time" # type filters if query.filter_type == "papers" or query.filter_type is None: |