Added "match left return left" and "match right return right" in RelationPartSpans.
diff --git a/src/main/java/de/ids_mannheim/korap/query/spans/RelationPartSpans.java b/src/main/java/de/ids_mannheim/korap/query/spans/RelationPartSpans.java
index 04af3e5..03b2f9c 100644
--- a/src/main/java/de/ids_mannheim/korap/query/spans/RelationPartSpans.java
+++ b/src/main/java/de/ids_mannheim/korap/query/spans/RelationPartSpans.java
@@ -254,12 +254,19 @@
                     id = matcheeSpans.getSpanId();
                 }
 
-                if (!inverse && r.getRightId() == id) {
-                    r.sortRight = false;
-                    candidateRelations.add(r);
-                } else if (inverse && r.getLeftId() == id) {
-                    r.sortRight = true;
-                    candidateRelations.add(r);
+                //if (!inverse && r.getRightId() == id) {
+                if (!inverse){
+                    if (matchRight && r.getRightId() == id ||
+                            !matchRight && r.getLeftId() == id){
+                        r.sortRight = false;
+                        candidateRelations.add(r);
+                    }                
+                } else if (inverse) {// && r.getLeftId() == id) {
+                    if (matchRight && r.getRightId() == id ||
+                            !matchRight && r.getLeftId() == id){
+                        r.sortRight = true;
+                        candidateRelations.add(r);
+                    }
                 }
                 i++;
             } else if (endPos <= matcheeSpans.end()) {
diff --git a/src/test/java/de/ids_mannheim/korap/index/TestRelationIndex.java b/src/test/java/de/ids_mannheim/korap/index/TestRelationIndex.java
index 81c3d67..4bc4355 100644
--- a/src/test/java/de/ids_mannheim/korap/index/TestRelationIndex.java
+++ b/src/test/java/de/ids_mannheim/korap/index/TestRelationIndex.java
@@ -288,12 +288,6 @@
 		kr = ki.search(wq,(short) 20);
 		assertEquals((long) 12, kr.getTotalResults());
 		
-		/*for (KorapMatch km : kr.getMatches()){		
-			System.out.println(km.getStartPos() +","+km.getEndPos()
-			//	+" "+km.getSnippetBrackets()
-			);
-		}*/		
-		
 		// child-of with attr func-obj
 		wq = new SpanWithAttributeQuery(srq, 
 				new SpanAttributeQuery( 
@@ -334,6 +328,67 @@
 		
 	}
 	
+	@Test
+    public void testCase10() throws IOException {
+        ki.addDoc(createFieldDoc2());
+        ki.commit();
+        
+        // return all children that are NP
+        SpanRelationPartQuery rv = new SpanRelationPartQuery(
+                new SpanRelationQuery(
+                        new SpanTermQuery(new Term("base",">:child-of")),true
+                ), 
+                new SpanElementQuery("base","np"), 
+                false, false, true); 
+                
+        kr = ki.search(rv,(short) 10);
+        
+        assertEquals(4, kr.getTotalResults());
+        assertEquals(0,kr.getMatch(0).getStartPos());
+        assertEquals(1,kr.getMatch(0).getEndPos());
+        assertEquals(2,kr.getMatch(1).getStartPos());
+        assertEquals(4,kr.getMatch(1).getEndPos());
+        assertEquals(2,kr.getMatch(2).getStartPos());
+        assertEquals(7,kr.getMatch(2).getEndPos());
+        assertEquals(5,kr.getMatch(3).getStartPos());
+        assertEquals(7,kr.getMatch(3).getEndPos());
+        
+        // return all parents that are NP
+        rv = new SpanRelationPartQuery(
+                new SpanRelationQuery(
+                        new SpanTermQuery(new Term("base",">:child-of")),true
+                ), 
+                new SpanElementQuery("base","np"), 
+                true, true, true); 
+                
+        kr = ki.search(rv,(short) 10);
+
+        assertEquals(7, kr.getTotalResults());
+        assertEquals(0,kr.getMatch(0).getStartPos());
+        assertEquals(1,kr.getMatch(0).getEndPos());
+        assertEquals(2,kr.getMatch(1).getStartPos());
+        assertEquals(4,kr.getMatch(1).getEndPos());
+        assertEquals(2,kr.getMatch(2).getStartPos());
+        assertEquals(4,kr.getMatch(2).getEndPos());
+        assertEquals(2,kr.getMatch(3).getStartPos());
+        assertEquals(7,kr.getMatch(3).getEndPos());
+        assertEquals(2,kr.getMatch(4).getStartPos());
+        assertEquals(7,kr.getMatch(4).getEndPos());
+        assertEquals(5,kr.getMatch(5).getStartPos());
+        assertEquals(7,kr.getMatch(5).getEndPos());
+        assertEquals(5,kr.getMatch(6).getStartPos());
+        assertEquals(7,kr.getMatch(6).getEndPos());     
+        
+//       for (KorapMatch km : kr.getMatches()){        
+//            System.out.println(km.getStartPos() +","+km.getEndPos()
+//                    //  +" "+km.getSnippetBrackets()
+//            );
+//       }  
+    
+
+   }
+	
+	
 	/** Relation with variable
 	 * 	match right, return left
 	 * 	sort by right, then sort by left