SEARCH-2379: Update the whole ASPECT list when updating a Document, that allows removing removed aspects

This commit is contained in:
Angel Borroy
2020-08-17 16:43:39 +02:00
parent 072241a252
commit e92a587f40

View File

@@ -1716,7 +1716,7 @@ public class SolrInformationServer implements InformationServer
.orElse(false); .orElse(false);
addDocCmd.solrDoc = isIndexed addDocCmd.solrDoc = isIndexed
? populateWithMetadata(basicDocument(nodeMetaData, DOC_TYPE_NODE, PartialSolrInputDocument::new), nodeMetaData) ? populateWithMetadata(basicDocument(nodeMetaData, DOC_TYPE_NODE, PartialSolrInputDocument::new), nodeMetaData, nmdp)
: basicDocument(nodeMetaData, DOC_TYPE_UNINDEXED_NODE, SolrInputDocument::new); : basicDocument(nodeMetaData, DOC_TYPE_UNINDEXED_NODE, SolrInputDocument::new);
processor.processAdd(addDocCmd); processor.processAdd(addDocCmd);
} }
@@ -2073,7 +2073,7 @@ public class SolrInformationServer implements InformationServer
addDocCmd.solrDoc = addDocCmd.solrDoc =
populateWithMetadata(basicDocument(nodeMetaData, DOC_TYPE_NODE, PartialSolrInputDocument::new), populateWithMetadata(basicDocument(nodeMetaData, DOC_TYPE_NODE, PartialSolrInputDocument::new),
nodeMetaData); nodeMetaData, nmdp);
processor.processAdd(addDocCmd); processor.processAdd(addDocCmd);
this.trackerStats.addNodeTime(System.nanoTime() - start); this.trackerStats.addNodeTime(System.nanoTime() - start);
@@ -2097,9 +2097,9 @@ public class SolrInformationServer implements InformationServer
} }
} }
private SolrInputDocument populateWithMetadata(SolrInputDocument document, NodeMetaData metadata) private SolrInputDocument populateWithMetadata(SolrInputDocument document, NodeMetaData metadata, NodeMetaDataParameters nmdp)
{ {
populateFields(metadata, document); populateFields(metadata, document, nmdp);
LOGGER.debug("Document size (fields) after getting fields from node {} metadata: {}", metadata.getId(), document.size()); LOGGER.debug("Document size (fields) after getting fields from node {} metadata: {}", metadata.getId(), document.size());
@@ -2114,40 +2114,44 @@ public class SolrInformationServer implements InformationServer
return document; return document;
} }
private void populateFields(NodeMetaData metadata, SolrInputDocument doc) private void populateFields(NodeMetaData metadata, SolrInputDocument doc, NodeMetaDataParameters nmdp)
{ {
doc.setField(FIELD_TYPE, metadata.getType().toString()); doc.setField(FIELD_TYPE, metadata.getType().toString());
notNullOrEmpty(metadata.getAspects()) if (nmdp.isIncludeAspects())
.stream() {
.filter(Objects::nonNull) doc.removeField(FIELD_ASPECT);
.forEach(aspect -> { notNullOrEmpty(metadata.getAspects())
doc.addField(FIELD_ASPECT, aspect.toString()); .stream()
if(aspect.equals(ContentModel.ASPECT_GEOGRAPHIC)) .filter(Objects::nonNull)
{ .forEach(aspect -> {
Optional<Double> latitude = doc.addField(FIELD_ASPECT, aspect.toString());
ofNullable(metadata.getProperties().get(ContentModel.PROP_LATITUDE)) if(aspect.equals(ContentModel.ASPECT_GEOGRAPHIC))
.map(StringPropertyValue.class::cast)
.map(StringPropertyValue::getValue)
.map(Utils::doubleOrNull)
.filter(value -> -90d <= value && value <= 90d);
Optional<Double> longitude =
ofNullable(metadata.getProperties().get(ContentModel.PROP_LONGITUDE))
.map(StringPropertyValue.class::cast)
.map(StringPropertyValue::getValue)
.map(Utils::doubleOrNull)
.filter(value -> -180d <= value && value <= 180d);
if (latitude.isPresent() && longitude.isPresent())
{ {
doc.setField(FIELD_GEO, latitude.get() + ", " + longitude.get()); Optional<Double> latitude =
ofNullable(metadata.getProperties().get(ContentModel.PROP_LATITUDE))
.map(StringPropertyValue.class::cast)
.map(StringPropertyValue::getValue)
.map(Utils::doubleOrNull)
.filter(value -> -90d <= value && value <= 90d);
Optional<Double> longitude =
ofNullable(metadata.getProperties().get(ContentModel.PROP_LONGITUDE))
.map(StringPropertyValue.class::cast)
.map(StringPropertyValue::getValue)
.map(Utils::doubleOrNull)
.filter(value -> -180d <= value && value <= 180d);
if (latitude.isPresent() && longitude.isPresent())
{
doc.setField(FIELD_GEO, latitude.get() + ", " + longitude.get());
}
else
{
LOGGER.warning("Skipping missing geo data on node {}", metadata.getId());
}
} }
else });
{ }
LOGGER.warning("Skipping missing geo data on node {}", metadata.getId());
}
}
});
doc.setField(FIELD_ISNODE, "T"); doc.setField(FIELD_ISNODE, "T");
doc.setField(FIELD_TENANT, AlfrescoSolrDataModel.getTenantId(metadata.getTenantDomain())); doc.setField(FIELD_TENANT, AlfrescoSolrDataModel.getTenantId(metadata.getTenantDomain()));