multisearch for eoscdatatasourcetypes
This commit is contained in:
parent
1271f9cf43
commit
7a2ce6b2ad
|
@ -1,5 +1,6 @@
|
||||||
package eu.dnetlib.openaire.dsm.dao;
|
package eu.dnetlib.openaire.dsm.dao;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
|
@ -55,6 +56,11 @@ public class DatasourceSpecs {
|
||||||
case search:
|
case search:
|
||||||
expressions.add(likeSearch(ds, cb, e));
|
expressions.add(likeSearch(ds, cb, e));
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case multiSearch:
|
||||||
|
expressions.add(likeSearchList(ds, cb, e));
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case searchOrgs:
|
case searchOrgs:
|
||||||
// search by case insensitive organization's country
|
// search by case insensitive organization's country
|
||||||
|
@ -100,6 +106,11 @@ public class DatasourceSpecs {
|
||||||
|
|
||||||
expressions.add(likeSearch(api, cb, e));
|
expressions.add(likeSearch(api, cb, e));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case multiSearch:
|
||||||
|
expressions.add(likeSearchList(api, cb, e));
|
||||||
|
|
||||||
|
break;
|
||||||
case searchOrgs:
|
case searchOrgs:
|
||||||
throw new DsmRuntimeException("not implemented");
|
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);
|
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
|
// search by ID, managed. exact match
|
||||||
private static Predicate exactSearch(final Root<?> r, final CriteriaBuilder cb, final Entry<FilterName, Object> e) {
|
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));
|
return cb.equal(r.get(e.getKey().name()), getValue(e));
|
||||||
|
|
|
@ -33,9 +33,10 @@ public enum FilterName {
|
||||||
case contactemail:
|
case contactemail:
|
||||||
case registeredby:
|
case registeredby:
|
||||||
case typology:
|
case typology:
|
||||||
case eoscDatasourceType:
|
|
||||||
case platform:
|
case platform:
|
||||||
return FilterType.search;
|
return FilterType.search;
|
||||||
|
case eoscDatasourceType:
|
||||||
|
return FilterType.multiSearch;
|
||||||
case country:
|
case country:
|
||||||
return FilterType.searchOrgs;
|
return FilterType.searchOrgs;
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
package eu.dnetlib.openaire.dsm.domain;
|
package eu.dnetlib.openaire.dsm.domain;
|
||||||
|
|
||||||
public enum FilterType {
|
public enum FilterType {
|
||||||
exact, search, searchOrgs
|
exact,
|
||||||
|
search,
|
||||||
|
searchOrgs,
|
||||||
|
multiSearch
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue