@@ -82,22 +82,22 @@ function getEntityNodesWithRelated(entityTypeIRIs, relatedEntityTypeIRIs, predic
8282 let joinOnObjectIri = op . on ( op . col ( "firstObjectIRI" ) , op . col ( "firstObjectIRI" ) ) ;
8383 let fullPlan = subjectPlan . joinLeftOuter ( firstLevelConnectionsPlan , joinOn ) . limit ( limit ) ;
8484 if ( entityTypeIRIs . length > 1 ) {
85- let otherEntityIRIs = op . fromSPARQL ( `PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
86- PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
87- SELECT ?subjectIRI ? docURI ?predicateIRI (MIN(?anyPredicateLabel) as ?predicateLabel) ?firstObjectIRI (MIN(?anyObjectLabel) as ?objectLabel) WHERE {
88- ?subjectIRI rdf:type @entityTypeIRIs;
89- rdfs:isDefinedBy ?docURI;
90- ?predicateIRI ? firstObjectIRI.
91- ?firstObjectIRI rdf:type @entityTypeIRIs .
92- OPTIONAL {
93- ?predicateIRI @labelIRI ?anyPredicateLabel.
94- }
95- OPTIONAL {
96- ?firstObjectIRI @labelIRI ?anyObjectLabel.
97- }
98- }
99- GROUP BY ?subjectIRI ?docURI ?predicateIRI ?firstObjectIRI
100- ` ) ;
85+ let otherEntityIRIs = op . fromSPARQL ( `PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> SELECT ?subjectIRI ?docURI ?predicateIRI (MIN(?anyPredicateLabel) as ?predicateLabel) ?firstObjectIRI (MIN(?docObjectURI) AS ?firstDocURI) (MIN(?anyObjectLabel) as ?objectLabel) WHERE {
86+ ?subjectIRI rdf:type @entityTypeIRIs;
87+ rdfs:isDefinedBy ? docURI;
88+ ?predicateIRI ?firstObjectIRI.
89+ ?firstObjectIRI rdf:type @entityTypeIRIs.
90+ ? firstObjectIRI rdf:type @entityTypeIRIs;
91+ rdfs:isDefinedBy ?docObjectURI .
92+ OPTIONAL {
93+ ?predicateIRI @labelIRI ?anyPredicateLabel.
94+ }
95+ OPTIONAL {
96+ ?firstObjectIRI @labelIRI ?anyObjectLabel.
97+ }
98+ }
99+ GROUP BY ?subjectIRI ?docURI ?predicateIRI ?firstObjectIRI
100+ ` ) ;
101101 fullPlan = fullPlan . union ( subjectPlan . joinLeftOuter ( otherEntityIRIs , joinOn ) . limit ( limit ) ) ;
102102 }
103103 // Can't run concept specific queries before ML 10.0-9 due to BugTrack https://bugtrack.marklogic.com/57077
@@ -351,13 +351,18 @@ function getNodeLabel(objectIRIArr, objectUri) {
351351 return label ;
352352}
353353
354+ function shouldCreateGroupNode ( item , entityType , entityTypeIds , isSearch ) {
355+ let allEntitiesAreSelected = entityTypeIds . length === fn . count ( fn . collection ( entityLib . getModelCollection ( ) ) ) ;
356+ return fn . exists ( item . nodeCount ) && fn . head ( item . nodeCount ) > 1
357+ && ! ( allEntitiesAreSelected === true && isSearch === true ) && ! ( entityTypeIds . includes ( entityType ) && isSearch === true ) ;
358+ }
359+
354360function graphResultsToNodesAndEdges ( result , entityTypeIds = [ ] , isSearch = true , excludeOriginNode = false ) {
355361 const nodesByID = { } ;
356362 const edgesByID = { } ;
357363 const docUriToSubjectIri = { } ;
358364 const distinctIriPredicateCombos = { } ;
359365 const groupNodeCount = { } ;
360- let allEntitiesAreSelected = entityTypeIds . length === fn . count ( fn . collection ( entityLib . getModelCollection ( ) ) ) ;
361366 const getEdgeCount = ( iri ) => {
362367 if ( ! distinctIriPredicateCombos [ iri ] ) {
363368 return 0 ;
@@ -397,7 +402,6 @@ function graphResultsToNodesAndEdges(result, entityTypeIds = [], isSearch = true
397402 }
398403
399404 const getUrisByIRI = ( iri ) => Object . keys ( docUriToSubjectIri ) . filter ( key => docUriToSubjectIri [ key ] . includes ( iri ) ) ;
400-
401405 for ( const item of result ) {
402406 let resultPropertiesOnHover = [ ] ;
403407 let newLabel = "" ;
@@ -474,7 +478,7 @@ function graphResultsToNodesAndEdges(result, entityTypeIds = [], isSearch = true
474478 if ( ! nodesByID [ key ] ) {
475479 let objectNode = { } ;
476480 objectNode . id = key ;
477- objectNode . docUri = isDocument ? key : null ;
481+ objectNode . docUri = isDocument ? key : item . firstDocURI ? item . firstDocURI : null ;
478482 objectNode . docIRI = objectIRI ;
479483 objectNode . label = isDocument ? getNodeLabel ( objectIRIArr , key ) : ( fn . string ( item . conceptLabel ) || objectIRIArr [ objectIRIArr . length - 1 ] ) ;
480484 resultPropertiesOnHover = isDocument ? entityLib . getValuesPropertiesOnHover ( key , objectEntityType , hubCentralConfig ) : "" ;
@@ -512,7 +516,7 @@ function graphResultsToNodesAndEdges(result, entityTypeIds = [], isSearch = true
512516 } ;
513517 }
514518 }
515- } else if ( fn . exists ( item . nodeCount ) && fn . head ( item . nodeCount ) > 1 && ! ( allEntitiesAreSelected === true && isSearch === true ) ) {
519+ } else if ( shouldCreateGroupNode ( item , objectIRIArr [ objectIRIArr . length - 2 ] , entityTypeIds , isSearch ) ) {
516520 const entityType = objectIRIArr [ objectIRIArr . length - 2 ] ;
517521 const objectId = originId + "-" + item . predicateIRI + "-" + entityType ;
518522 let edge = { } ;
0 commit comments