FileDocCategorySizeDatePackage
TestSpans.javaAPI DocApache Lucene 1.4.33090Sat Jul 10 08:49:52 BST 2004org.apache.lucene.search.spans

TestSpans

public class TestSpans extends TestCase
Copyright 2004 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, this);
  
public org.apache.lucene.search.spans.SpanTermQuerymakeSpanTermQuery(java.lang.String text)


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

    SpanTermQuery w1 = makeSpanTermQuery("w1");
    SpanTermQuery w2 = makeSpanTermQuery("w2");
    SpanTermQuery w3 = makeSpanTermQuery("w3");
    boolean ordered = true;
    SpanNearQuery snq = new SpanNearQuery( new SpanQuery[]{w1,w2,w3}, slop, ordered);
    checkHits(snq, expectedDocs);
  
public voidsetUp()


       
    RAMDirectory directory = new RAMDirectory();
    IndexWriter writer= new IndexWriter(directory, new WhitespaceAnalyzer(), true);
    StringBuffer buffer = new StringBuffer();
    for (int i = 0; i < docFields.length; i++) {
      Document doc = new Document();
      doc.add(Field.Text(field, docFields[i]));
      writer.addDocument(doc);
    }
    writer.close();
    searcher = new IndexSearcher(directory);
  
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});