diff --git a/src/edu/cornell/mannlib/vitro/webapp/searchindex/extensions/LabelsAcrossContextNodes.java b/src/edu/cornell/mannlib/vitro/webapp/searchindex/extensions/LabelsAcrossContextNodes.java index 95766a3e..c1d8c7f9 100644 --- a/src/edu/cornell/mannlib/vitro/webapp/searchindex/extensions/LabelsAcrossContextNodes.java +++ b/src/edu/cornell/mannlib/vitro/webapp/searchindex/extensions/LabelsAcrossContextNodes.java @@ -283,15 +283,15 @@ public class LabelsAcrossContextNodes implements IndexingUriFinder, private static final String LOCATE_PARTNERS_WITHOUT_RESTRICTION = "" + "SELECT ?partner \n" // + "WHERE { \n" // - + " ?uri ?incoming ?contextNode . \n" // - + " ?contextNode ?outgoing ?partner . \n" // + + " ?partner ?incoming ?contextNode . \n" // + + " ?contextNode ?outgoing ?uri . \n" // + " FILTER( ?uri != ?partner ) \n" // + "} \n"; private static final String LOCATE_PARTNERS_ON_CONTEXT_NODE_TYPE = "" + "SELECT ?partner \n" // + "WHERE { \n" // - + " ?uri ?incoming ?contextNode . \n" // - + " ?contextNode ?outgoing ?partner . \n" // + + " ?partner ?incoming ?contextNode . \n" // + + " ?contextNode ?outgoing ?uri . \n" // + " ?contextNode a ?nodeType . \n" // + " FILTER( ?uri != ?partner ) \n" // + "} \n"; @@ -316,18 +316,15 @@ public class LabelsAcrossContextNodes implements IndexingUriFinder, * If this is a "label" statement, check to see if the subject has any * acceptable partners across acceptable context nodes. * - * If this is a statement that involves the specified outgoing property on - * an acceptable context node, check to see if there are any other - * acceptable partners on this node. - * - * We could also check for statements that involve the specified incoming - * property, but they should happen in pairs with the "outgoing" statements. + * If this is a statement that involves the specified incoming property on + * an acceptable context node, check to see if there are any acceptable + * partners on this node. */ @Override public List findAdditionalURIsToIndex(Statement stmt) { if (isLabelStatement(stmt)) { return filterByType(locatePartners(stmt)); - } else if (isOutgoingStatementOnAcceptableContextNode(stmt)) { + } else if (isIncomingStatementOnAcceptableContextNode(stmt)) { return filterByType(locateOtherPartners(stmt)); } return Collections.emptyList(); @@ -371,11 +368,11 @@ public class LabelsAcrossContextNodes implements IndexingUriFinder, .getStringFields("partner").flattenToSet(); } - private boolean isOutgoingStatementOnAcceptableContextNode(Statement stmt) { + private boolean isIncomingStatementOnAcceptableContextNode(Statement stmt) { String subjectUri = stmt.getSubject().getURI(); String predicateUri = stmt.getPredicate().getURI(); - if (outgoingPropertyUri.equals(predicateUri) + if (incomingPropertyUri.equals(predicateUri) && (contextNodeClasses.isEmpty() || isAnyMatch( contextNodeClasses, getTypes(subjectUri)))) { return true; diff --git a/test/edu/cornell/mannlib/vitro/webapp/searchindex/extensions/LabelsAcrossContextNodesTest.java b/test/edu/cornell/mannlib/vitro/webapp/searchindex/extensions/LabelsAcrossContextNodesTest.java index a2b5d69d..64d2579a 100644 --- a/test/edu/cornell/mannlib/vitro/webapp/searchindex/extensions/LabelsAcrossContextNodesTest.java +++ b/test/edu/cornell/mannlib/vitro/webapp/searchindex/extensions/LabelsAcrossContextNodesTest.java @@ -278,42 +278,42 @@ public class LabelsAcrossContextNodesTest extends AbstractTestClass { } @Test - public void relates_returnsPartner() { + public void relatedBy_returnsPartner() { setTypeRestrictions(); setContextNodeTypes(); - exerciseUriFinder(stmt(URI_POSITION1, CORE_RELATES, URI_PERSON1)); + exerciseUriFinder(stmt(URI_POSITION1, CORE_RELATED_BY, URI_PERSON1)); assertExpectedUris(URI_ORGANIZATION1); } @Test - public void relates_inclusiveTypeRestriction_returnsPartner() { + public void relatedBy_inclusiveTypeRestriction_returnsPartner() { setTypeRestrictions(FOAF_ORGANIZATION); setContextNodeTypes(); - exerciseUriFinder(stmt(URI_POSITION1, CORE_RELATES, URI_PERSON1)); + exerciseUriFinder(stmt(URI_POSITION1, CORE_RELATED_BY, URI_PERSON1)); assertExpectedUris(URI_ORGANIZATION1); } @Test - public void relates_exclusiveTypeRestriction_returnsNothing() { + public void relatedBy_exclusiveTypeRestriction_returnsNothing() { setTypeRestrictions(CORE_ADVISING_RELATIONSHIP); setContextNodeTypes(); - exerciseUriFinder(stmt(URI_POSITION1, CORE_RELATES, URI_PERSON1)); + exerciseUriFinder(stmt(URI_POSITION1, CORE_RELATED_BY, URI_PERSON1)); assertExpectedUris(); } @Test - public void relates_inclusiveContextType_returnsPartner() { + public void relatedBy_inclusiveContextType_returnsPartner() { setTypeRestrictions(); setContextNodeTypes(CORE_POSITION); - exerciseUriFinder(stmt(URI_POSITION1, CORE_RELATES, URI_PERSON1)); + exerciseUriFinder(stmt(URI_POSITION1, CORE_RELATED_BY, URI_PERSON1)); assertExpectedUris(URI_ORGANIZATION1); } @Test - public void relates_exclusiveContextType_returnsNothing() { + public void relatedBy_exclusiveContextType_returnsNothing() { setTypeRestrictions(); setContextNodeTypes(CORE_ADVISING_RELATIONSHIP); - exerciseUriFinder(stmt(URI_POSITION1, CORE_RELATES, URI_PERSON1)); + exerciseUriFinder(stmt(URI_POSITION1, CORE_RELATED_BY, URI_PERSON1)); assertExpectedUris(); }