From 360726ab527ca736f3ff8359e8c6101926017e3e Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Thu, 17 Sep 2020 23:14:22 -0700 Subject: 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. --- fatcat_scholar/search.py | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) (limited to 'fatcat_scholar/search.py') 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: -- cgit v1.2.3