package de.ids_mannheim.korap.query.spans;

import java.io.IOException;
import java.util.Map;

import org.apache.lucene.index.AtomicReaderContext;
import org.apache.lucene.index.Term;
import org.apache.lucene.index.TermContext;
import org.apache.lucene.util.Bits;

import de.ids_mannheim.korap.query.SimpleSpanQuery;

/**	SegmentSpans is an enumeration of Span matches, which ensures that two spans 
 * 	have exactly the same start and end positions.
 * 
 * 	@author margaretha 
 * */
public class SegmentSpans extends SimpleSpans {	
	
    public SegmentSpans (SimpleSpanQuery simpleSpanQuery,
  	      AtomicReaderContext context,
  	      Bits acceptDocs,
  	      Map<Term,TermContext> termContexts) throws IOException {
    	this(simpleSpanQuery, context, acceptDocs, termContexts, true);    	
    }
    
    public SegmentSpans (SimpleSpanQuery simpleSpanQuery,
	      AtomicReaderContext context,
	      Bits acceptDocs,
	      Map<Term,TermContext> termContexts,
	      boolean collectPayloads) throws IOException {		 			
		super(simpleSpanQuery, context, acceptDocs, termContexts,collectPayloads);
	}

    /** Check weather the start and end positions of the current 
     * 	firstspan and secondspan are identical. 
  	 * */
	protected int findMatch() {
		
		if (firstSpans.start() == secondSpans.start() &&
			firstSpans.end() == secondSpans.end() ){
			matchDocNumber = firstSpans.doc();
			matchStartPosition = firstSpans.start();
			matchEndPosition = firstSpans.end();			
			return 0;
		}
		else if (firstSpans.start() < secondSpans.start())
			return -1;
		
		return 1;
	}	
}

@@ -309,16 +309,69 @@
 anQuery;
+%0Aimport de.ids_mannheim.korap.query.SpanSegmentQuery;
 %0A%0A/**%09Se
@@ -612,33 +612,35 @@
 s (S
-impleSpanQuery simpleSpan
+panSegmentQuery spanSegment
 Quer
@@ -783,25 +783,26 @@
  %09this(s
-impleSpan
+panSegment
 Query, c
@@ -888,33 +888,35 @@
 s (S
-impleSpanQuery simpleSpan
+panSegmentQuery spanSegment
 Quer
@@ -1089,25 +1089,26 @@
 %09super(s
-impleSpan
+panSegment
 Query, c
@@ -1606,16 +1606,61 @@
 .start()
+ %7C%7C %0A%09%09%09%09firstSpans.end() %3C secondSpans.end()
 )%0A%09%09%09ret

Add a constraint to forward secondspans