multisearch for eoscdatatasourcetypes
This commit is contained in:
parent
1271f9cf43
commit
7a2ce6b2ad
|
@ -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<FilterName, Object> 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<FilterName, Object> e) {
|
||||
return cb.equal(r.get(e.getKey().name()), getValue(e));
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
package eu.dnetlib.openaire.dsm.domain;
|
||||
|
||||
public enum FilterType {
|
||||
exact, search, searchOrgs
|
||||
exact,
|
||||
search,
|
||||
searchOrgs,
|
||||
multiSearch
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue