FileDocCategorySizeDatePackage
TestSpans.javaAPI DocApache Lucene 1.95853Mon Feb 20 09:19:28 GMT 2006org.apache.lucene.search.spans

TestSpans

public class TestSpans extends TestCase
Copyright 2005 The Apache Software Foundation Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Fields Summary
private IndexSearcher
searcher
public static final String
field
private String[]
docFields
Constructors Summary
Methods Summary
private voidcheckHits(org.apache.lucene.search.Query query, int[] results)

    CheckHits.checkHits(query, field, searcher, results);
  
public org.apache.lucene.search.spans.SpanTermQuerymakeSpanTermQuery(java.lang.String text)


      
    return new SpanTermQuery(new Term(field, text));
  
public voidorderedSlopTest1Equal(int slop, int[] expectedDocs)

    orderedSlopTest3SQ(
       makeSpanTermQuery("u2"),
       makeSpanTermQuery("u2"),
       makeSpanTermQuery("u1"),
       slop,
       expectedDocs);
  
public voidorderedSlopTest3(int slop, int[] expectedDocs)

    orderedSlopTest3SQ(
       makeSpanTermQuery("w1"),
       makeSpanTermQuery("w2"),
       makeSpanTermQuery("w3"),
       slop,
       expectedDocs);
  
public voidorderedSlopTest3Equal(int slop, int[] expectedDocs)

    orderedSlopTest3SQ(
       makeSpanTermQuery("w1"),
       makeSpanTermQuery("w3"),
       makeSpanTermQuery("w3"),
       slop,
       expectedDocs);
  
private voidorderedSlopTest3SQ(org.apache.lucene.search.spans.SpanQuery q1, org.apache.lucene.search.spans.SpanQuery q2, org.apache.lucene.search.spans.SpanQuery q3, int slop, int[] expectedDocs)

    boolean ordered = true;
    SpanNearQuery snq = new SpanNearQuery( new SpanQuery[]{q1,q2,q3}, slop, ordered);
    checkHits(snq, expectedDocs);
  
public voidsetUp()


       
    RAMDirectory directory = new RAMDirectory();
    IndexWriter writer= new IndexWriter(directory, new WhitespaceAnalyzer(), true);
    for (int i = 0; i < docFields.length; i++) {
      Document doc = new Document();
      doc.add(new Field(field, docFields[i], Field.Store.YES, Field.Index.TOKENIZED));
      writer.addDocument(doc);
    }
    writer.close();
    searcher = new IndexSearcher(directory);
//System.out.println("set up " + getName());
  
public voidtestSpanNearOrdered01()

    orderedSlopTest3(0, new int[] {0});
  
public voidtestSpanNearOrdered02()

    orderedSlopTest3(1, new int[] {0,1});
  
public voidtestSpanNearOrdered03()

    orderedSlopTest3(2, new int[] {0,1,2});
  
public voidtestSpanNearOrdered04()

    orderedSlopTest3(3, new int[] {0,1,2,3});
  
public voidtestSpanNearOrdered05()

    orderedSlopTest3(4, new int[] {0,1,2,3});
  
public voidtestSpanNearOrderedEqual01()

    orderedSlopTest3Equal(0, new int[] {});
  
public voidtestSpanNearOrderedEqual02()

    orderedSlopTest3Equal(1, new int[] {1});
  
public voidtestSpanNearOrderedEqual03()

    orderedSlopTest3Equal(2, new int[] {1});
  
public voidtestSpanNearOrderedEqual04()

    orderedSlopTest3Equal(3, new int[] {1,3});
  
public voidtestSpanNearOrderedEqual11()

    orderedSlopTest1Equal(0, new int[] {4});
  
public voidtestSpanNearOrderedEqual12()

    orderedSlopTest1Equal(0, new int[] {4});
  
public voidtestSpanNearOrderedEqual13()

    orderedSlopTest1Equal(1, new int[] {4,5,6});
  
public voidtestSpanNearOrderedEqual14()

    orderedSlopTest1Equal(2, new int[] {4,5,6,7});
  
public voidtestSpanNearOrderedEqual15()

    orderedSlopTest1Equal(3, new int[] {4,5,6,7});
  
public voidtestSpanNearOrderedOverlap()

    boolean ordered = true;
    int slop = 1;
    SpanNearQuery snq = new SpanNearQuery(
                              new SpanQuery[] {
                                makeSpanTermQuery("t1"),
                                makeSpanTermQuery("t2"),
                                makeSpanTermQuery("t3") },
                              slop,
                              ordered);
    Spans spans = snq.getSpans(searcher.getIndexReader());

    assertTrue("first range", spans.next());
    assertEquals("first doc", 11, spans.doc());
    assertEquals("first start", 0, spans.start());
    assertEquals("first end", 4, spans.end());

    assertTrue("second range", spans.next());
    assertEquals("second doc", 11, spans.doc());
    assertEquals("second start", 2, spans.start());
    assertEquals("second end", 6, spans.end());

    assertFalse("third range", spans.next());