@@ -0,0 +1,2812 @@
+package org.apache.lucene.search.spans;%0A%0A/**%0A * Licensed to the Apache Software Foundation (ASF) under one or more%0A * contributor license agreements.  See the NOTICE file distributed with%0A * this work for additional information regarding copyright ownership.%0A * The ASF licenses this file to You under the Apache License, Version 2.0%0A * (the %22License%22); you may not use this file except in compliance with%0A * the License.  You may obtain a copy of the License at%0A *%0A *     http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0A%0Aimport org.apache.lucene.analysis.Analyzer;%0Aimport org.apache.lucene.analysis.MockAnalyzer;%0Aimport org.apache.lucene.analysis.MockTokenizer;%0Aimport org.apache.lucene.document.Document;%0Aimport org.apache.lucene.document.Field;%0Aimport org.apache.lucene.index.IndexReader;%0Aimport org.apache.lucene.index.RandomIndexWriter;%0Aimport org.apache.lucene.index.Term;%0Aimport org.apache.lucene.search.IndexSearcher;%0Aimport org.apache.lucene.store.Directory;%0Aimport org.apache.lucene.util.LuceneTestCase;%0Aimport org.apache.lucene.util.automaton.CharacterRunAutomaton;%0Aimport org.apache.lucene.util.automaton.RegExp;%0A%0Apublic class TestSpanFirstQuery extends LuceneTestCase %7B%0A  public void testStartPositions() throws Exception %7B%0A    Directory dir = newDirectory();%0A    %0A    // mimic StopAnalyzer%0A    CharacterRunAutomaton stopSet = new CharacterRunAutomaton(new RegExp(%22the%7Ca%7Cof%22).toAutomaton());%0A    Analyzer analyzer = new MockAnalyzer(MockTokenizer.SIMPLE, true, stopSet, true);%0A    %0A    RandomIndexWriter writer = new RandomIndexWriter(random, dir, analyzer);%0A    Document doc = new Document();%0A    doc.add(newField(%22field%22, %22the quick brown fox%22, Field.Index.ANALYZED));%0A    writer.addDocument(doc);%0A    Document doc2 = new Document();%0A    doc2.add(newField(%22field%22, %22quick brown fox%22, Field.Index.ANALYZED));%0A    writer.addDocument(doc2);%0A    %0A    IndexReader reader = writer.getReader();%0A    IndexSearcher searcher = new IndexSearcher(reader);%0A    %0A    // user queries on %22starts-with quick%22%0A    SpanQuery sfq = new SpanFirstQuery(new SpanTermQuery(new Term(%22field%22, %22quick%22)), 1);%0A    assertEquals(1, searcher.search(sfq, 10).totalHits);%0A    %0A    // user queries on %22starts-with the quick%22%0A    SpanQuery include = new SpanFirstQuery(new SpanTermQuery(new Term(%22field%22, %22quick%22)), 2);%0A    sfq = new SpanNotQuery(include, sfq);%0A    assertEquals(1, searcher.search(sfq, 10).totalHits);%0A    %0A    writer.close();%0A    searcher.close();%0A    reader.close();%0A    dir.close();%0A  %7D%0A%7D%0A

add this test from the discussion