mirror of
https://github.com/Alfresco/SearchServices.git
synced 2025-10-01 14:41:19 +00:00
[MNT-23154] Enable multiple content fields in the same document
This commit is contained in:
@@ -36,6 +36,7 @@ import java.net.MalformedURLException;
|
|||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLClassLoader;
|
import java.net.URLClassLoader;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
@@ -45,6 +46,7 @@ import java.util.Properties;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.ThreadPoolExecutor;
|
import java.util.concurrent.ThreadPoolExecutor;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
import org.alfresco.error.AlfrescoRuntimeException;
|
import org.alfresco.error.AlfrescoRuntimeException;
|
||||||
import org.alfresco.model.ContentModel;
|
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 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 static class TenantDbId
|
||||||
{
|
{
|
||||||
public String tenant;
|
public String tenant;
|
||||||
public Long dbId;
|
public Long dbId;
|
||||||
|
|
||||||
|
private List<ContentPropertySpecs> contentPropertySpecsList;
|
||||||
|
|
||||||
public Map<String, Object> optionalBag = new HashMap<>();
|
public Map<String, Object> optionalBag = new HashMap<>();
|
||||||
|
|
||||||
public void setProperty(String name, Object value)
|
public void setProperty(String name, Object value)
|
||||||
{
|
{
|
||||||
optionalBag.put(name, value);
|
optionalBag.put(name, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean hasAtLeastOneContentProperty() {
|
||||||
|
return contentPropertySpecsList != null && !contentPropertySpecsList.isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addContentPropertiesSpecs(List<ContentPropertySpecs> specsList)
|
||||||
|
{
|
||||||
|
contentPropertySpecsList = Collections.unmodifiableList(specsList);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Stream<ContentPropertySpecs> contentPropertySpecsStream() {
|
||||||
|
return contentPropertySpecsList.stream();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum FieldUse
|
public enum FieldUse
|
||||||
|
@@ -28,8 +28,10 @@ package org.alfresco.solr;
|
|||||||
|
|
||||||
import static java.util.Arrays.asList;
|
import static java.util.Arrays.asList;
|
||||||
import static java.util.Arrays.stream;
|
import static java.util.Arrays.stream;
|
||||||
|
import static java.util.Collections.emptyList;
|
||||||
import static java.util.Optional.empty;
|
import static java.util.Optional.empty;
|
||||||
import static java.util.Optional.ofNullable;
|
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_ACLID;
|
||||||
import static org.alfresco.repo.search.adaptor.QueryConstants.FIELD_ACLTXCOMMITTIME;
|
import static org.alfresco.repo.search.adaptor.QueryConstants.FIELD_ACLTXCOMMITTIME;
|
||||||
import static org.alfresco.repo.search.adaptor.QueryConstants.FIELD_ACLTXID;
|
import static org.alfresco.repo.search.adaptor.QueryConstants.FIELD_ACLTXID;
|
||||||
@@ -1006,27 +1008,17 @@ public class SolrInformationServer implements InformationServer
|
|||||||
String idString = id.stringValue();
|
String idString = id.stringValue();
|
||||||
TenantDbId tenantAndDbId = AlfrescoSolrDataModel.decodeNodeDocumentId(idString);
|
TenantDbId tenantAndDbId = AlfrescoSolrDataModel.decodeNodeDocumentId(idString);
|
||||||
|
|
||||||
if (enabledIndexCustomContent)
|
tenantAndDbId.addContentPropertiesSpecs(
|
||||||
{
|
enabledIndexCustomContent
|
||||||
|
? document.getFields().stream()
|
||||||
document.getFields().stream()
|
.filter(field -> field.name().startsWith(AlfrescoSolrDataModel.CONTENT_S_LOCALE_PREFIX))
|
||||||
.filter(field -> field.name().startsWith(AlfrescoSolrDataModel.CONTENT_S_LOCALE_PREFIX))
|
.map(field -> new AlfrescoSolrDataModel.ContentPropertySpecs(field.name(),field.stringValue()))
|
||||||
.findFirst()
|
.collect(toList())
|
||||||
.ifPresent(field -> {
|
: ofNullable(document.getField(CONTENT_LOCALE_FIELD))
|
||||||
tenantAndDbId.setProperty(CONTENT_FIELD_NAME, field.name());
|
.map(IndexableField::stringValue)
|
||||||
tenantAndDbId.setProperty(CONTENT_LOCALE, field.stringValue());
|
.map(value -> new AlfrescoSolrDataModel.ContentPropertySpecs(CONTENT_LOCALE_FIELD, value))
|
||||||
});
|
.map(Collections::singletonList)
|
||||||
}
|
.orElse(emptyList()));
|
||||||
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.setProperty(
|
tenantAndDbId.setProperty(
|
||||||
LATEST_APPLIED_CONTENT_VERSION_ID,
|
LATEST_APPLIED_CONTENT_VERSION_ID,
|
||||||
@@ -1904,7 +1896,7 @@ public class SolrInformationServer implements InformationServer
|
|||||||
nmdp.setMaxResults(1);
|
nmdp.setMaxResults(1);
|
||||||
// Gets only one
|
// Gets only one
|
||||||
Optional<Collection<NodeMetaData>> nodeMetaDatas = getNodesMetaDataFromRepository(nmdp);
|
Optional<Collection<NodeMetaData>> nodeMetaDatas = getNodesMetaDataFromRepository(nmdp);
|
||||||
allNodeMetaDatas.addAll(nodeMetaDatas.orElse(Collections.emptyList()));
|
allNodeMetaDatas.addAll(nodeMetaDatas.orElse(emptyList()));
|
||||||
}
|
}
|
||||||
|
|
||||||
return allNodeMetaDatas;
|
return allNodeMetaDatas;
|
||||||
@@ -1958,7 +1950,7 @@ public class SolrInformationServer implements InformationServer
|
|||||||
docRef.tenant,
|
docRef.tenant,
|
||||||
docRef.dbId));
|
docRef.dbId));
|
||||||
|
|
||||||
if (docRef.optionalBag.containsKey(CONTENT_FIELD_NAME))
|
if (docRef.hasAtLeastOneContentProperty())
|
||||||
{
|
{
|
||||||
addContentToDoc(docRef, doc, docRef.dbId);
|
addContentToDoc(docRef, doc, docRef.dbId);
|
||||||
}
|
}
|
||||||
@@ -2010,8 +2002,8 @@ public class SolrInformationServer implements InformationServer
|
|||||||
categorizeNodes(nodes, nodeIdsToNodes, nodeStatusToNodeIds);
|
categorizeNodes(nodes, nodeIdsToNodes, nodeStatusToNodeIds);
|
||||||
|
|
||||||
List<Long> deletedNodeIds = notNullOrEmpty(nodeStatusToNodeIds.get(SolrApiNodeStatus.DELETED));
|
List<Long> deletedNodeIds = notNullOrEmpty(nodeStatusToNodeIds.get(SolrApiNodeStatus.DELETED));
|
||||||
List<Long> shardDeletedNodeIds = Collections.emptyList();
|
List<Long> shardDeletedNodeIds = emptyList();
|
||||||
List<Long> shardUpdatedNodeIds = Collections.emptyList();
|
List<Long> shardUpdatedNodeIds = emptyList();
|
||||||
if (cascadeTrackingEnabled())
|
if (cascadeTrackingEnabled())
|
||||||
{
|
{
|
||||||
shardDeletedNodeIds = notNullOrEmpty(nodeStatusToNodeIds.get(SolrApiNodeStatus.NON_SHARD_DELETED));
|
shardDeletedNodeIds = notNullOrEmpty(nodeStatusToNodeIds.get(SolrApiNodeStatus.NON_SHARD_DELETED));
|
||||||
@@ -2463,7 +2455,7 @@ public class SolrInformationServer implements InformationServer
|
|||||||
dataModel.getIndexedFieldNamesForProperty(propertyQName).getFields()
|
dataModel.getIndexedFieldNamesForProperty(propertyQName).getFields()
|
||||||
.stream()
|
.stream()
|
||||||
.map(FieldInstance::getField)
|
.map(FieldInstance::getField)
|
||||||
.collect(Collectors.toList()));
|
.collect(toList()));
|
||||||
|
|
||||||
for (PropertyValue singleValue : typedValue.getValues())
|
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);
|
docRef.contentPropertySpecsStream()
|
||||||
String locale = (String) docRef.optionalBag.get(CONTENT_LOCALE);
|
.forEach(propertySpecs -> {
|
||||||
String qNamePart = fieldName.substring(AlfrescoSolrDataModel.CONTENT_S_LOCALE_PREFIX.length());
|
try {
|
||||||
QName propertyQName = QName.createQName(qNamePart);
|
var propertyQName = QName.createQName(propertySpecs.fieldName.substring(AlfrescoSolrDataModel.CONTENT_S_LOCALE_PREFIX.length()));
|
||||||
addContentPropertyToDocUsingAlfrescoRepository(doc, propertyQName, dbId, locale);
|
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)
|
if (mlTextPropertyValue == null)
|
||||||
{
|
{
|
||||||
return Collections.emptyList();
|
return emptyList();
|
||||||
}
|
}
|
||||||
|
|
||||||
List<String> values = new ArrayList<>();
|
List<String> values = new ArrayList<>();
|
||||||
@@ -2917,7 +2913,7 @@ public class SolrInformationServer implements InformationServer
|
|||||||
.stream()
|
.stream()
|
||||||
.filter(Objects::nonNull)
|
.filter(Objects::nonNull)
|
||||||
.map(mlTextPropertyValue::getValue)
|
.map(mlTextPropertyValue::getValue)
|
||||||
.collect(Collectors.toList());
|
.collect(toList());
|
||||||
|
|
||||||
if (!localisedValues.isEmpty())
|
if (!localisedValues.isEmpty())
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user