MNT-23525: content is indexed according to "cm:isContentIndexed" value (#1698)

This commit is contained in:
Vítor Moreira
2023-04-05 09:22:47 +01:00
committed by GitHub
parent c7f23c27c2
commit c3dd096b10
2 changed files with 66 additions and 31 deletions

View File

@@ -121,7 +121,6 @@ import java.util.function.Function;
import java.util.function.Supplier;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.zip.GZIPInputStream;
import com.carrotsearch.hppc.IntArrayList;
@@ -1767,7 +1766,7 @@ public class SolrInformationServer implements InformationServer
.map(StringPropertyValue::getValue)
.map(Boolean::parseBoolean)
.orElse(true);
addDocCmd.solrDoc = isIndexed
? populateWithMetadata(
basicDocument(nodeMetaData, DOC_TYPE_NODE, PartialSolrInputDocument::new),
@@ -2175,7 +2174,12 @@ public class SolrInformationServer implements InformationServer
document,
contentIndexingHasBeenEnabledOnThisInstance);
keepContentFields(document);
if( isContentIndexedForNode( metadata.getProperties()) )
{
keepContentFields(document);
} else {
deleteContentField(document);
}
LOGGER.debug("Document size (fields) after getting properties from node {} metadata: {}", metadata.getId(), document.size());
@@ -2407,11 +2411,6 @@ public class SolrInformationServer implements InformationServer
contentIndexingHasBeenEnabledOnThisInstance
&& contentIndexingHasBeenRequestedForThisNode;
if (!contentIndexingIsEnabled)
{
markAsContentInSynch(document);
}
final BiConsumer<String, Object> setValue = document::setField;
final BiConsumer<String, Object> addValue = document::addField;
final BiConsumer<String, Object> collectName = (name, value) -> addFieldIfNotSet(document, name);
@@ -2817,7 +2816,7 @@ public class SolrInformationServer implements InformationServer
}
}
private void keepContentFields(PartialSolrInputDocument doc)
private void applyContentFields(PartialSolrInputDocument doc, BiConsumer<PartialSolrInputDocument, String> consumer)
{
String qNamePart = CONTENT_LOCALE_FIELD.substring(AlfrescoSolrDataModel.CONTENT_S_LOCALE_PREFIX.length());
QName propertyQName = QName.createQName(qNamePart);
@@ -2825,20 +2824,28 @@ public class SolrInformationServer implements InformationServer
dataModel.getIndexedFieldForSpecializedPropertyMetadata(propertyQName, AlfrescoSolrDataModel.SpecializedFieldType.TRANSFORMATION_STATUS)
.getFields()
.stream()
.forEach(field -> doc.keepField(field.getField()));
.forEach(field -> consumer.accept(doc, field.getField()));
dataModel.getIndexedFieldForSpecializedPropertyMetadata(propertyQName, AlfrescoSolrDataModel.SpecializedFieldType.TRANSFORMATION_EXCEPTION)
.getFields()
.stream()
.forEach(field -> doc.keepField(field.getField()));
.forEach(field -> consumer.accept(doc, field.getField()));
dataModel.getIndexedFieldForSpecializedPropertyMetadata(propertyQName, AlfrescoSolrDataModel.SpecializedFieldType.TRANSFORMATION_TIME)
.getFields()
.stream()
.forEach(field -> doc.keepField(field.getField()));
.forEach(field -> consumer.accept(doc, field.getField()));
doc.keepField(FINGERPRINT_FIELD);
doc.keepField(dataModel.getStoredContentField(propertyQName));
consumer.accept(doc, FINGERPRINT_FIELD);
consumer.accept(doc, dataModel.getStoredContentField(propertyQName));
}
private void deleteContentField(PartialSolrInputDocument doc) {
applyContentFields( doc, (doc2, field) -> doc2.removeField(field) );
}
private void keepContentFields(PartialSolrInputDocument doc)
{
applyContentFields(doc, (doc2, field) -> doc2.keepField(field));
}
private String languageFrom(String locale)

View File

@@ -254,23 +254,7 @@ public class AlfrescoSolrTrackerIT extends AbstractAlfrescoSolrIT
logger.info("#################### Passed Eighth Test ##############################");
//Add document with isContentIndexed=false
Transaction txnNoContent = getTransaction(0, 1);
Node noContentNode = getNode(txnNoContent, acl, Node.SolrApiNodeStatus.UPDATED);
NodeMetaData noContentMetaData = getNodeMetaData(noContentNode, txnNoContent, acl, "mike", null, false);
noContentMetaData.getProperties().put(ContentModel.PROP_IS_CONTENT_INDEXED, new StringPropertyValue("false"));
noContentMetaData.getProperties().put(ContentModel.PROP_CONTENT, new ContentPropertyValue(Locale.UK, 298L, "UTF-8", "text/json", null));
indexTransaction(txnNoContent, list(noContentNode), list(noContentMetaData));
//This tests that the mime type has been added for this document. It is the only document with text/json in the index.
waitForDocCount(new TermQuery(new Term("content@s__mimetype@{http://www.alfresco.org/model/content/1.0}content", "text/json")), 1, MAX_WAIT_TIME);
//Many of the tests beyond this point rely on a specific count of documents in the index that have content.
//This document should not have had the content indexed so the tests following will pass.
//If the content had been indexed the tests following this one would have failed.
//This proves that the ContentModel.PROP_IS_CONTENT_INDEXED property is being followed by the tracker
testIsContentIndexed(acl);
//Try bulk loading
@@ -435,4 +419,48 @@ public class AlfrescoSolrTrackerIT extends AbstractAlfrescoSolrIT
waitForDocCount(new TermQuery(new Term("content@s___t@{http://www.alfresco.org/model/content/1.0}content", Long.toString(errorNode.getId()))), 1, MAX_WAIT_TIME);
logger.info("#################### Passed Nineteenth Test ##############################");
}
// test cm:isContentIndexed property
private void testIsContentIndexed(Acl acl) throws Exception
{
// number of existing documents before running this test
final int previousNumberOfDocuments = 2;
waitForDocCount(new TermQuery(new Term("content@s___t@{http://www.alfresco.org/model/content/1.0}content", "world")), previousNumberOfDocuments, MAX_WAIT_TIME);
// adds a document with cm:indexControl aspect with "cm:isIndexed" as true and "cm:isContentIndexed" is false
Transaction txnWithAspect = getTransaction(0, 1);
Node aspectNode = getNode(txnWithAspect, acl, Node.SolrApiNodeStatus.UPDATED);
NodeMetaData aspectNodeMetaData = getNodeMetaData(aspectNode, txnWithAspect, acl, "mike", null, false);
aspectNodeMetaData.getAspects().add(ContentModel.ASPECT_INDEX_CONTROL);
aspectNodeMetaData.getProperties().put(ContentModel.PROP_IS_INDEXED, new StringPropertyValue("true"));
aspectNodeMetaData.getProperties().put(ContentModel.PROP_IS_CONTENT_INDEXED, new StringPropertyValue("false"));
indexTransaction(txnWithAspect, list(aspectNode), list(aspectNodeMetaData));
// the new document is not supposed to be indexed
waitForDocCount(new TermQuery(new Term("content@s___t@{http://www.alfresco.org/model/content/1.0}content", "world")), previousNumberOfDocuments, MAX_WAIT_TIME);
// switch "cm:isContentIndexed" from false to true
Transaction txnContentIndexedFromTrueToFalse = getTransaction(0, 1);
aspectNodeMetaData.getProperties().put(ContentModel.PROP_IS_CONTENT_INDEXED, new StringPropertyValue("true"));
indexTransaction(txnContentIndexedFromTrueToFalse, list(aspectNode), list(aspectNodeMetaData));
// it's supposed the new document to be indexed
waitForDocCount(new TermQuery(new Term("content@s___t@{http://www.alfresco.org/model/content/1.0}content", "world")), previousNumberOfDocuments+1, MAX_WAIT_TIME);
// switch "cm:isContentIndexed" from true to false
Transaction txnContentIndexedFromFalseToTrue = getTransaction(0, 1);
aspectNodeMetaData.getProperties().put(ContentModel.PROP_IS_CONTENT_INDEXED, new StringPropertyValue("false"));
indexTransaction(txnContentIndexedFromFalseToTrue, list(aspectNode), list(aspectNodeMetaData));
// it's supposed the new document not to be indexed again
waitForDocCount(new TermQuery(new Term("content@s___t@{http://www.alfresco.org/model/content/1.0}content", "world")), previousNumberOfDocuments, MAX_WAIT_TIME);
// delete document
Transaction txnDeleteContentIndexed = getTransaction(1, 0);
indexTransaction(txnDeleteContentIndexed, list(aspectNode), list(aspectNodeMetaData));
// it's supposed to the new document disappear
waitForDocCount(new TermQuery(new Term("content@s___t@{http://www.alfresco.org/model/content/1.0}content", "world")), previousNumberOfDocuments, MAX_WAIT_TIME);
}
}