From 39d4eaedb4bf3764533844a87a29ed973eeb08fd Mon Sep 17 00:00:00 2001 From: Uthpala Herath Date: Fri, 22 Nov 2024 16:01:46 -0500 Subject: [PATCH] Implemented DOI search function --- materials/templates/materials/search.html | 4 ++++ materials/views.py | 11 +++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/materials/templates/materials/search.html b/materials/templates/materials/search.html index 69ae32b..8178ece 100644 --- a/materials/templates/materials/search.html +++ b/materials/templates/materials/search.html @@ -113,6 +113,10 @@
Search for Materials
text = "Search by author's name"; $('#search_text').attr('placeholder', text); $('#explanatory_text').text(text); + } else if (this.value == 'doi') { + text = "Search by DOI, e.g. 10.1515/ncrs-1999-0320"; + $('#search_text').attr('placeholder', text); + $('#explanatory_text').text(text); } else { text = ''; $('#search_text').attr('placeholder', text); diff --git a/materials/views.py b/materials/views.py index 1aaaa26..a3cba2e 100644 --- a/materials/views.py +++ b/materials/views.py @@ -191,6 +191,7 @@ class SearchFormView(generic.TemplateView): ["inorganic", "Inorganic Component"], ["author", "Author"], ["band_gap", "Band gap"], + ["doi", "DOI"], ] def get(self, request): @@ -240,8 +241,14 @@ def post(self, request): "is_experimental" ) # Get the is_experimental value + # If DOI search + if search_term == "doi": + systems = models.System.objects.filter( + dataset__reference__doi_isbn__icontains=search_text + ).distinct() + # If band gap search - if ( + elif ( search_term == "band_gap" and band_gap_min is not None and band_gap_max is not None @@ -549,7 +556,7 @@ class DatasetViewSet(viewsets.ReadOnlyModelViewSet): "primary_property__name": ["exact", "contains"], "secondary_property__name": ["exact", "contains"], "reference": ["exact"], - #"dimensionality": ["exact"], + # "dimensionality": ["exact"], } search_fields = filterset_fields