fix elastic recent search
This commit is contained in:
parent
7158fdb6c3
commit
08d29aac5b
|
@ -49,9 +49,15 @@ public class DmpElasticQuery extends ElasticQuery<DmpElasticEntity, UUID> {
|
||||||
private Collection<DmpAccessType> accessTypes;
|
private Collection<DmpAccessType> accessTypes;
|
||||||
private Collection<Integer> versions;
|
private Collection<Integer> versions;
|
||||||
private Collection<UUID> groupIds;
|
private Collection<UUID> groupIds;
|
||||||
|
private NestedCollaboratorElasticQuery dmpUserSubQuery;
|
||||||
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
|
private EnumSet<AuthorizationFlags> authorize = EnumSet.of(AuthorizationFlags.None);
|
||||||
|
|
||||||
|
|
||||||
|
public DmpElasticQuery dmpSubQuery(NestedCollaboratorElasticQuery subQuery) {
|
||||||
|
this.dmpUserSubQuery = subQuery;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public DmpElasticQuery like(String value) {
|
public DmpElasticQuery like(String value) {
|
||||||
this.like = value;
|
this.like = value;
|
||||||
return this;
|
return this;
|
||||||
|
@ -296,6 +302,9 @@ public class DmpElasticQuery extends ElasticQuery<DmpElasticEntity, UUID> {
|
||||||
if (this.accessTypes != null) {
|
if (this.accessTypes != null) {
|
||||||
predicates.add(this.contains(this.elasticFieldOf(DmpElasticEntity._accessType), this.accessTypes.stream().map(x-> x.getValue()).collect(Collectors.toList()).toArray(new Short[this.accessTypes.size()]))._toQuery());
|
predicates.add(this.contains(this.elasticFieldOf(DmpElasticEntity._accessType), this.accessTypes.stream().map(x-> x.getValue()).collect(Collectors.toList()).toArray(new Short[this.accessTypes.size()]))._toQuery());
|
||||||
}
|
}
|
||||||
|
if (this.dmpUserSubQuery != null) {
|
||||||
|
predicates.add(this.nestedQuery( this.dmpUserSubQuery.nestedPath(DmpElasticEntity._collaborators)).build()._toQuery());
|
||||||
|
}
|
||||||
|
|
||||||
if (!predicates.isEmpty()) {
|
if (!predicates.isEmpty()) {
|
||||||
return this.and(predicates);
|
return this.and(predicates);
|
||||||
|
|
|
@ -1,11 +1,6 @@
|
||||||
package org.opencdmp.elastic.query;
|
package org.opencdmp.elastic.query;
|
||||||
|
|
||||||
import co.elastic.clients.elasticsearch._types.query_dsl.Query;
|
import co.elastic.clients.elasticsearch._types.query_dsl.Query;
|
||||||
import org.opencdmp.authorization.AuthorizationFlags;
|
|
||||||
import org.opencdmp.commons.enums.DmpAccessType;
|
|
||||||
import org.opencdmp.commons.enums.DmpStatus;
|
|
||||||
import org.opencdmp.commons.enums.DmpVersionStatus;
|
|
||||||
import org.opencdmp.elastic.data.DmpElasticEntity;
|
|
||||||
import org.opencdmp.elastic.data.nested.NestedDmpElasticEntity;
|
|
||||||
import gr.cite.tools.data.query.FieldResolver;
|
import gr.cite.tools.data.query.FieldResolver;
|
||||||
import gr.cite.tools.data.query.QueryFactory;
|
import gr.cite.tools.data.query.QueryFactory;
|
||||||
import gr.cite.tools.elastic.configuration.ElasticProperties;
|
import gr.cite.tools.elastic.configuration.ElasticProperties;
|
||||||
|
@ -14,6 +9,11 @@ import gr.cite.tools.elastic.query.ElasticField;
|
||||||
import gr.cite.tools.elastic.query.ElasticFields;
|
import gr.cite.tools.elastic.query.ElasticFields;
|
||||||
import gr.cite.tools.elastic.query.ElasticInnerObjectQuery;
|
import gr.cite.tools.elastic.query.ElasticInnerObjectQuery;
|
||||||
import gr.cite.tools.elastic.query.ElasticNestedQuery;
|
import gr.cite.tools.elastic.query.ElasticNestedQuery;
|
||||||
|
import org.opencdmp.commons.enums.DmpAccessType;
|
||||||
|
import org.opencdmp.commons.enums.DmpStatus;
|
||||||
|
import org.opencdmp.commons.enums.DmpVersionStatus;
|
||||||
|
import org.opencdmp.elastic.data.DescriptionElasticEntity;
|
||||||
|
import org.opencdmp.elastic.data.nested.NestedDmpElasticEntity;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.config.BeanDefinition;
|
import org.springframework.beans.factory.config.BeanDefinition;
|
||||||
import org.springframework.context.annotation.Scope;
|
import org.springframework.context.annotation.Scope;
|
||||||
|
@ -35,9 +35,13 @@ public class InnerObjectDmpElasticQuery extends ElasticInnerObjectQuery<InnerObj
|
||||||
private Collection<DmpAccessType> accessTypes;
|
private Collection<DmpAccessType> accessTypes;
|
||||||
private Collection<Integer> versions;
|
private Collection<Integer> versions;
|
||||||
private Collection<UUID> groupIds;
|
private Collection<UUID> groupIds;
|
||||||
|
private NestedCollaboratorElasticQuery dmpUserSubQuery;
|
||||||
|
|
||||||
|
|
||||||
|
public InnerObjectDmpElasticQuery dmpSubQuery(NestedCollaboratorElasticQuery subQuery) {
|
||||||
|
this.dmpUserSubQuery = subQuery;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public InnerObjectDmpElasticQuery like(String value) {
|
public InnerObjectDmpElasticQuery like(String value) {
|
||||||
this.like = value;
|
this.like = value;
|
||||||
|
@ -159,7 +163,7 @@ public class InnerObjectDmpElasticQuery extends ElasticInnerObjectQuery<InnerObj
|
||||||
|
|
||||||
|
|
||||||
private final QueryFactory queryFactory;
|
private final QueryFactory queryFactory;
|
||||||
@Autowired()
|
@Autowired
|
||||||
public InnerObjectDmpElasticQuery(ElasticsearchTemplate elasticsearchTemplate, ElasticProperties elasticProperties, QueryFactory queryFactory) {
|
public InnerObjectDmpElasticQuery(ElasticsearchTemplate elasticsearchTemplate, ElasticProperties elasticProperties, QueryFactory queryFactory) {
|
||||||
super(elasticsearchTemplate, elasticProperties);
|
super(elasticsearchTemplate, elasticProperties);
|
||||||
this.queryFactory = queryFactory;
|
this.queryFactory = queryFactory;
|
||||||
|
@ -179,34 +183,37 @@ public class InnerObjectDmpElasticQuery extends ElasticInnerObjectQuery<InnerObj
|
||||||
protected Query applyFilters() {
|
protected Query applyFilters() {
|
||||||
List<Query> predicates = new ArrayList<>();
|
List<Query> predicates = new ArrayList<>();
|
||||||
|
|
||||||
if (like != null && !like.isBlank()) {
|
if (this.like != null && !this.like.isBlank()) {
|
||||||
if (!like.startsWith("*")) like = "*" + like;
|
if (!this.like.startsWith("*")) this.like = "*" + this.like;
|
||||||
if (!like.endsWith("*")) like = like + "*";
|
if (!this.like.endsWith("*")) this.like = this.like + "*";
|
||||||
ElasticFields elasticFields = new ElasticFields(this.entityClass(), List.of(this.getInnerPath()));
|
ElasticFields elasticFields = new ElasticFields(this.entityClass(), List.of(this.getInnerPath()));
|
||||||
elasticFields.add(DmpElasticEntity._label, true);
|
elasticFields.add(NestedDmpElasticEntity._label, true);
|
||||||
elasticFields.add(DmpElasticEntity._descriptions, true);
|
elasticFields.add(NestedDmpElasticEntity._description, true);
|
||||||
predicates.add(this.like(elasticFields, List.of(like))._toQuery());
|
predicates.add(this.like(elasticFields, List.of(this.like))._toQuery());
|
||||||
}
|
}
|
||||||
if (ids != null) {
|
if (this.ids != null) {
|
||||||
predicates.add(this.containsUUID(this.elasticFieldOf(DmpElasticEntity._id).disableInfer(true), ids)._toQuery());
|
predicates.add(this.containsUUID(this.elasticFieldOf(NestedDmpElasticEntity._id).disableInfer(true), this.ids)._toQuery());
|
||||||
}
|
}
|
||||||
if (groupIds != null) {
|
if (this.groupIds != null) {
|
||||||
predicates.add(this.containsUUID(this.elasticFieldOf(DmpElasticEntity._groupId).disableInfer(true), groupIds)._toQuery());
|
predicates.add(this.containsUUID(this.elasticFieldOf(NestedDmpElasticEntity._groupId).disableInfer(true), this.groupIds)._toQuery());
|
||||||
}
|
}
|
||||||
if (versions != null) {
|
if (this.versions != null) {
|
||||||
predicates.add(this.contains(this.elasticFieldOf(DmpElasticEntity._version).disableInfer(true), versions.toArray(new Integer[versions.size()]))._toQuery());
|
predicates.add(this.contains(this.elasticFieldOf(NestedDmpElasticEntity._version).disableInfer(true), this.versions.toArray(new Integer[this.versions.size()]))._toQuery());
|
||||||
}
|
}
|
||||||
if (excludedIds != null) {
|
if (this.excludedIds != null) {
|
||||||
predicates.add(this.not(this.containsUUID(this.elasticFieldOf(DmpElasticEntity._id).disableInfer(true), excludedIds)._toQuery())._toQuery());
|
predicates.add(this.not(this.containsUUID(this.elasticFieldOf(NestedDmpElasticEntity._id).disableInfer(true), this.excludedIds)._toQuery())._toQuery());
|
||||||
}
|
}
|
||||||
if (statuses != null) {
|
if (this.statuses != null) {
|
||||||
predicates.add(this.contains(this.elasticFieldOf(DmpElasticEntity._status).disableInfer(true), statuses.stream().map(x-> x.getValue()).collect(Collectors.toList()).toArray(new Short[statuses.size()]))._toQuery());
|
predicates.add(this.contains(this.elasticFieldOf(NestedDmpElasticEntity._status).disableInfer(true), this.statuses.stream().map(x-> x.getValue()).collect(Collectors.toList()).toArray(new Short[this.statuses.size()]))._toQuery());
|
||||||
}
|
}
|
||||||
if (versionStatuses != null) {
|
if (this.versionStatuses != null) {
|
||||||
predicates.add(this.contains(this.elasticFieldOf(DmpElasticEntity._versionStatus).disableInfer(true), versionStatuses.stream().map(x-> x.getValue()).collect(Collectors.toList()).toArray(new Short[versionStatuses.size()]))._toQuery());
|
predicates.add(this.contains(this.elasticFieldOf(NestedDmpElasticEntity._versionStatus).disableInfer(true), this.versionStatuses.stream().map(x-> x.getValue()).collect(Collectors.toList()).toArray(new Short[this.versionStatuses.size()]))._toQuery());
|
||||||
}
|
}
|
||||||
if (accessTypes != null) {
|
if (this.accessTypes != null) {
|
||||||
predicates.add(this.contains(this.elasticFieldOf(DmpElasticEntity._accessType).disableInfer(true), accessTypes.stream().map(x-> x.getValue()).collect(Collectors.toList()).toArray(new Short[accessTypes.size()]))._toQuery());
|
predicates.add(this.contains(this.elasticFieldOf(NestedDmpElasticEntity._accessType).disableInfer(true), this.accessTypes.stream().map(x-> x.getValue()).collect(Collectors.toList()).toArray(new Short[this.accessTypes.size()]))._toQuery());
|
||||||
|
}
|
||||||
|
if (this.dmpUserSubQuery != null) {
|
||||||
|
predicates.add(this.nestedQuery( this.dmpUserSubQuery.nestedPath(DescriptionElasticEntity._dmp + "." + NestedDmpElasticEntity._collaborators)).build()._toQuery());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!predicates.isEmpty()) {
|
if (!predicates.isEmpty()) {
|
||||||
|
|
|
@ -152,7 +152,7 @@ public class DmpLookup extends Lookup {
|
||||||
if (this.versions != null) query.versions(this.versions);
|
if (this.versions != null) query.versions(this.versions);
|
||||||
if (this.versionStatuses != null) query.versionStatuses(this.versionStatuses);
|
if (this.versionStatuses != null) query.versionStatuses(this.versionStatuses);
|
||||||
if (this.dmpDescriptionTemplateSubQuery != null) throw new UnsupportedOperationException("");
|
if (this.dmpDescriptionTemplateSubQuery != null) throw new UnsupportedOperationException("");
|
||||||
if (this.dmpUserSubQuery != null) throw new UnsupportedOperationException("");
|
if (this.dmpUserSubQuery != null) query.dmpSubQuery(this.dmpUserSubQuery.enrichElasticInner(queryFactory));
|
||||||
|
|
||||||
this.enrichCommon(query);
|
this.enrichCommon(query);
|
||||||
|
|
||||||
|
@ -170,7 +170,7 @@ public class DmpLookup extends Lookup {
|
||||||
if (this.versions != null) query.versions(this.versions);
|
if (this.versions != null) query.versions(this.versions);
|
||||||
if (this.versionStatuses != null) query.versionStatuses(this.versionStatuses);
|
if (this.versionStatuses != null) query.versionStatuses(this.versionStatuses);
|
||||||
if (this.dmpDescriptionTemplateSubQuery != null) throw new UnsupportedOperationException("");
|
if (this.dmpDescriptionTemplateSubQuery != null) throw new UnsupportedOperationException("");
|
||||||
if (this.dmpUserSubQuery != null) throw new UnsupportedOperationException("");
|
if (this.dmpUserSubQuery != null) query.dmpSubQuery(this.dmpUserSubQuery.enrichElasticInner(queryFactory));
|
||||||
|
|
||||||
return query;
|
return query;
|
||||||
}
|
}
|
||||||
|
|
|
@ -84,11 +84,12 @@ public class DmpUserLookup extends Lookup {
|
||||||
return query;
|
return query;
|
||||||
}
|
}
|
||||||
|
|
||||||
public NestedCollaboratorElasticQuery enrichElastic(QueryFactory queryFactory) {
|
public NestedCollaboratorElasticQuery enrichElasticInner(QueryFactory queryFactory) {
|
||||||
NestedCollaboratorElasticQuery query = queryFactory.query(NestedCollaboratorElasticQuery.class);
|
NestedCollaboratorElasticQuery query = queryFactory.query(NestedCollaboratorElasticQuery.class);
|
||||||
if (this.ids != null) query.ids(this.ids);
|
if (this.ids != null) query.ids(this.ids);
|
||||||
if (this.userIds != null) query.userIds(this.userIds);
|
if (this.userIds != null) query.userIds(this.userIds);
|
||||||
if (this.userRoles != null) query.userRoles(this.userRoles);
|
if (this.userRoles != null) query.userRoles(this.userRoles);
|
||||||
|
if (this.sectionIds != null) throw new UnsupportedOperationException("");
|
||||||
|
|
||||||
this.enrichCommon(query);
|
this.enrichCommon(query);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue