diff --git a/search-services/alfresco-search/src/main/java/org/alfresco/solr/AlfrescoSolrDataModel.java b/search-services/alfresco-search/src/main/java/org/alfresco/solr/AlfrescoSolrDataModel.java index 293870c94..b3bd9f6d1 100644 --- a/search-services/alfresco-search/src/main/java/org/alfresco/solr/AlfrescoSolrDataModel.java +++ b/search-services/alfresco-search/src/main/java/org/alfresco/solr/AlfrescoSolrDataModel.java @@ -36,6 +36,7 @@ import java.net.MalformedURLException; import java.net.URL; import java.net.URLClassLoader; import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.LinkedList; @@ -45,6 +46,7 @@ import java.util.Properties; import java.util.Set; import java.util.concurrent.ThreadPoolExecutor; import java.util.stream.Collectors; +import java.util.stream.Stream; import org.alfresco.error.AlfrescoRuntimeException; import org.alfresco.model.ContentModel; @@ -128,17 +130,42 @@ import static org.alfresco.solr.SolrInformationServer.UNIT_OF_TIME_YEAR_FIELD_SU */ public class AlfrescoSolrDataModel implements QueryConstants { + public static class ContentPropertySpecs { + public final String fieldName; + public final String locale; + + public ContentPropertySpecs(String fieldName, String locale) { + this.fieldName = fieldName; + this.locale = locale; + } + } + public static class TenantDbId { public String tenant; public Long dbId; + private List contentPropertySpecsList; + public Map optionalBag = new HashMap<>(); public void setProperty(String name, Object value) { optionalBag.put(name, value); } + + public boolean hasAtLeastOneContentProperty() { + return contentPropertySpecsList != null && !contentPropertySpecsList.isEmpty(); + } + + public void addContentPropertiesSpecs(List specsList) + { + contentPropertySpecsList = Collections.unmodifiableList(specsList); + } + + public Stream contentPropertySpecsStream() { + return contentPropertySpecsList.stream(); + } } public enum FieldUse diff --git a/search-services/alfresco-search/src/main/java/org/alfresco/solr/SolrInformationServer.java b/search-services/alfresco-search/src/main/java/org/alfresco/solr/SolrInformationServer.java index da9077442..71809ad60 100644 --- a/search-services/alfresco-search/src/main/java/org/alfresco/solr/SolrInformationServer.java +++ b/search-services/alfresco-search/src/main/java/org/alfresco/solr/SolrInformationServer.java @@ -28,8 +28,10 @@ package org.alfresco.solr; import static java.util.Arrays.asList; import static java.util.Arrays.stream; +import static java.util.Collections.emptyList; import static java.util.Optional.empty; import static java.util.Optional.ofNullable; +import static java.util.stream.Collectors.toList; import static org.alfresco.repo.search.adaptor.QueryConstants.FIELD_ACLID; import static org.alfresco.repo.search.adaptor.QueryConstants.FIELD_ACLTXCOMMITTIME; import static org.alfresco.repo.search.adaptor.QueryConstants.FIELD_ACLTXID; @@ -1006,27 +1008,17 @@ public class SolrInformationServer implements InformationServer String idString = id.stringValue(); TenantDbId tenantAndDbId = AlfrescoSolrDataModel.decodeNodeDocumentId(idString); - if (enabledIndexCustomContent) - { - - document.getFields().stream() - .filter(field -> field.name().startsWith(AlfrescoSolrDataModel.CONTENT_S_LOCALE_PREFIX)) - .findFirst() - .ifPresent(field -> { - tenantAndDbId.setProperty(CONTENT_FIELD_NAME, field.name()); - tenantAndDbId.setProperty(CONTENT_LOCALE, field.stringValue()); - }); - } - else - { - ofNullable(document.getField(CONTENT_LOCALE_FIELD)) - .map(IndexableField::stringValue) - .ifPresent(value -> { - tenantAndDbId.setProperty(CONTENT_FIELD_NAME, CONTENT_LOCALE_FIELD); - tenantAndDbId.setProperty(CONTENT_LOCALE, value); - }); - } - + tenantAndDbId.addContentPropertiesSpecs( + enabledIndexCustomContent + ? document.getFields().stream() + .filter(field -> field.name().startsWith(AlfrescoSolrDataModel.CONTENT_S_LOCALE_PREFIX)) + .map(field -> new AlfrescoSolrDataModel.ContentPropertySpecs(field.name(),field.stringValue())) + .collect(toList()) + : ofNullable(document.getField(CONTENT_LOCALE_FIELD)) + .map(IndexableField::stringValue) + .map(value -> new AlfrescoSolrDataModel.ContentPropertySpecs(CONTENT_LOCALE_FIELD, value)) + .map(Collections::singletonList) + .orElse(emptyList())); tenantAndDbId.setProperty( LATEST_APPLIED_CONTENT_VERSION_ID, @@ -1904,7 +1896,7 @@ public class SolrInformationServer implements InformationServer nmdp.setMaxResults(1); // Gets only one Optional> nodeMetaDatas = getNodesMetaDataFromRepository(nmdp); - allNodeMetaDatas.addAll(nodeMetaDatas.orElse(Collections.emptyList())); + allNodeMetaDatas.addAll(nodeMetaDatas.orElse(emptyList())); } return allNodeMetaDatas; @@ -1958,7 +1950,7 @@ public class SolrInformationServer implements InformationServer docRef.tenant, docRef.dbId)); - if (docRef.optionalBag.containsKey(CONTENT_FIELD_NAME)) + if (docRef.hasAtLeastOneContentProperty()) { addContentToDoc(docRef, doc, docRef.dbId); } @@ -2010,8 +2002,8 @@ public class SolrInformationServer implements InformationServer categorizeNodes(nodes, nodeIdsToNodes, nodeStatusToNodeIds); List deletedNodeIds = notNullOrEmpty(nodeStatusToNodeIds.get(SolrApiNodeStatus.DELETED)); - List shardDeletedNodeIds = Collections.emptyList(); - List shardUpdatedNodeIds = Collections.emptyList(); + List shardDeletedNodeIds = emptyList(); + List shardUpdatedNodeIds = emptyList(); if (cascadeTrackingEnabled()) { shardDeletedNodeIds = notNullOrEmpty(nodeStatusToNodeIds.get(SolrApiNodeStatus.NON_SHARD_DELETED)); @@ -2463,7 +2455,7 @@ public class SolrInformationServer implements InformationServer dataModel.getIndexedFieldNamesForProperty(propertyQName).getFields() .stream() .map(FieldInstance::getField) - .collect(Collectors.toList())); + .collect(toList())); for (PropertyValue singleValue : typedValue.getValues()) { @@ -2736,13 +2728,17 @@ public class SolrInformationServer implements InformationServer } } - private void addContentToDoc(TenantDbId docRef, SolrInputDocument doc, long dbId) throws AuthenticationException, IOException + private void addContentToDoc(TenantDbId docRef, SolrInputDocument doc, long dbId) { - String fieldName = (String) docRef.optionalBag.get(CONTENT_FIELD_NAME); - String locale = (String) docRef.optionalBag.get(CONTENT_LOCALE); - String qNamePart = fieldName.substring(AlfrescoSolrDataModel.CONTENT_S_LOCALE_PREFIX.length()); - QName propertyQName = QName.createQName(qNamePart); - addContentPropertyToDocUsingAlfrescoRepository(doc, propertyQName, dbId, locale); + docRef.contentPropertySpecsStream() + .forEach(propertySpecs -> { + try { + var propertyQName = QName.createQName(propertySpecs.fieldName.substring(AlfrescoSolrDataModel.CONTENT_S_LOCALE_PREFIX.length())); + addContentPropertyToDocUsingAlfrescoRepository(doc, propertyQName, dbId, propertySpecs.locale); + } catch (AuthenticationException | IOException exception) { + throw new RuntimeException(exception); + } + }); } @@ -2855,7 +2851,7 @@ public class SolrInformationServer implements InformationServer { if (mlTextPropertyValue == null) { - return Collections.emptyList(); + return emptyList(); } List values = new ArrayList<>(); @@ -2917,7 +2913,7 @@ public class SolrInformationServer implements InformationServer .stream() .filter(Objects::nonNull) .map(mlTextPropertyValue::getValue) - .collect(Collectors.toList()); + .collect(toList()); if (!localisedValues.isEmpty()) {