diff --git a/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/dsm/dao/DatasourceSpecs.java b/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/dsm/dao/DatasourceSpecs.java index 7fc5958d..dcbb9dba 100644 --- a/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/dsm/dao/DatasourceSpecs.java +++ b/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/dsm/dao/DatasourceSpecs.java @@ -1,5 +1,6 @@ package eu.dnetlib.openaire.dsm.dao; +import java.util.Arrays; import java.util.List; import java.util.Map.Entry; @@ -55,6 +56,11 @@ public class DatasourceSpecs { case search: expressions.add(likeSearch(ds, cb, e)); + break; + + case multiSearch: + expressions.add(likeSearchList(ds, cb, e)); + break; case searchOrgs: // search by case insensitive organization's country @@ -100,6 +106,11 @@ public class DatasourceSpecs { expressions.add(likeSearch(api, cb, e)); break; + + case multiSearch: + expressions.add(likeSearchList(api, cb, e)); + + break; case searchOrgs: throw new DsmRuntimeException("not implemented"); } @@ -117,6 +128,23 @@ public class DatasourceSpecs { return cb.like(cb.lower(r.get(e.getKey().name())), WILDCARD + getValue(e) + WILDCARD); } + // substring, case insensitive, like based search + private static Predicate likeSearchList(final Root r, final CriteriaBuilder cb, final Entry e) { + final String key = e.getKey().name(); + + log.info("key : " + key); + log.info("val : " + e.getValue()); + + final Predicate[] arr = + Arrays.stream(e.getValue().toString().split(",")) + .map(String::toLowerCase) + .map(s -> cb.like(cb.lower(r.get(key)), WILDCARD + s + WILDCARD)) + .toArray(size -> new Predicate[size]); + + return cb.or(arr); + + } + // search by ID, managed. exact match private static Predicate exactSearch(final Root r, final CriteriaBuilder cb, final Entry e) { return cb.equal(r.get(e.getKey().name()), getValue(e)); diff --git a/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/dsm/domain/FilterName.java b/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/dsm/domain/FilterName.java index c929d920..2dbd67eb 100644 --- a/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/dsm/domain/FilterName.java +++ b/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/dsm/domain/FilterName.java @@ -33,9 +33,10 @@ public enum FilterName { case contactemail: case registeredby: case typology: - case eoscDatasourceType: case platform: return FilterType.search; + case eoscDatasourceType: + return FilterType.multiSearch; case country: return FilterType.searchOrgs; default: diff --git a/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/dsm/domain/FilterType.java b/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/dsm/domain/FilterType.java index 5d15adfd..a028e350 100644 --- a/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/dsm/domain/FilterType.java +++ b/apps/dnet-exporter-api/src/main/java/eu/dnetlib/openaire/dsm/domain/FilterType.java @@ -1,5 +1,8 @@ package eu.dnetlib.openaire.dsm.domain; public enum FilterType { - exact, search, searchOrgs + exact, + search, + searchOrgs, + multiSearch }