Skip to content

Commit

Permalink
SEARCH-2379: Update the whole PARENT list when updating a Document
Browse files Browse the repository at this point in the history
  • Loading branch information
aborroy committed Aug 18, 2020
1 parent d6fae59 commit 4917232
Showing 1 changed file with 30 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1716,7 +1716,7 @@ public void indexNode(Node node, boolean overwrite) throws IOException, JSONExce
.orElse(false);

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);
processor.processAdd(addDocCmd);
}
Expand Down Expand Up @@ -2073,7 +2073,7 @@ public void indexNodes(List<Node> nodes, boolean overwrite) throws IOException,

addDocCmd.solrDoc =
populateWithMetadata(basicDocument(nodeMetaData, DOC_TYPE_NODE, PartialSolrInputDocument::new),
nodeMetaData);
nodeMetaData, nmdp);
processor.processAdd(addDocCmd);

this.trackerStats.addNodeTime(System.nanoTime() - start);
Expand All @@ -2097,9 +2097,9 @@ public void indexNodes(List<Node> nodes, boolean overwrite) throws IOException,
}
}

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());

Expand All @@ -2114,7 +2114,7 @@ private SolrInputDocument populateWithMetadata(SolrInputDocument document, NodeM
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());
notNullOrEmpty(metadata.getAspects())
Expand Down Expand Up @@ -2165,31 +2165,35 @@ private void populateFields(NodeMetaData metadata, SolrInputDocument doc)
StringBuilder qNameBuffer = new StringBuilder();
StringBuilder assocTypeQNameBuffer = new StringBuilder();

notNullOrEmpty(metadata.getParentAssocs())
.forEach(childAssocRef -> {
if (qNameBuffer.length() > 0)
{
qNameBuffer.append(";/");
assocTypeQNameBuffer.append(";/");
}
qNameBuffer.append(ISO9075.getXPathName(childAssocRef.getQName()));
assocTypeQNameBuffer.append(ISO9075.getXPathName(childAssocRef.getTypeQName()));
doc.addField(FIELD_PARENT, childAssocRef.getParentRef().toString());

if (childAssocRef.isPrimary())
{
if(doc.getField(FIELD_PRIMARYPARENT) == null)
if (nmdp.isIncludeParentAssociations())
{
doc.removeField(FIELD_PARENT);
notNullOrEmpty(metadata.getParentAssocs())
.forEach(childAssocRef -> {
if (qNameBuffer.length() > 0)
{
doc.setField(FIELD_PRIMARYPARENT, childAssocRef.getParentRef().toString());
doc.setField(FIELD_PRIMARYASSOCTYPEQNAME, ISO9075.getXPathName(childAssocRef.getTypeQName()));
doc.setField(FIELD_PRIMARYASSOCQNAME, ISO9075.getXPathName(childAssocRef.getQName()));
qNameBuffer.append(";/");
assocTypeQNameBuffer.append(";/");
}
else
qNameBuffer.append(ISO9075.getXPathName(childAssocRef.getQName()));
assocTypeQNameBuffer.append(ISO9075.getXPathName(childAssocRef.getTypeQName()));
doc.addField(FIELD_PARENT, childAssocRef.getParentRef().toString());

if (childAssocRef.isPrimary())
{
LOGGER.warning("Duplicate primary parent for node id {}", metadata.getId());
if(doc.getField(FIELD_PRIMARYPARENT) == null)
{
doc.setField(FIELD_PRIMARYPARENT, childAssocRef.getParentRef().toString());
doc.setField(FIELD_PRIMARYASSOCTYPEQNAME, ISO9075.getXPathName(childAssocRef.getTypeQName()));
doc.setField(FIELD_PRIMARYASSOCQNAME, ISO9075.getXPathName(childAssocRef.getQName()));
}
else
{
LOGGER.warning("Duplicate primary parent for node id {}", metadata.getId());
}
}
}
});
});
}

ofNullable(metadata.getParentAssocs()).ifPresent(parents -> {
doc.addField(FIELD_ASSOCTYPEQNAME, assocTypeQNameBuffer.toString());
Expand Down

0 comments on commit 4917232

Please sign in to comment.