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

TestSpansAdvanced2

public class TestSpansAdvanced2 extends TestSpansAdvanced
Some expanded tests to make sure my patch doesn't break other SpanTermQuery functionality.
author
Reece Wilton

Fields Summary
Constructors Summary
Methods Summary
protected voidsetUp()
Initializes the tests by adding documents to the index.

        super.setUp();

        // create test index
        final IndexWriter writer = new IndexWriter(mDirectory, new StandardAnalyzer(), false);
        addDocument(writer, "A", "Should we, could we, would we?");
        addDocument(writer, "B", "It should.  Should it?");
        addDocument(writer, "C", "It shouldn't.");
        addDocument(writer, "D", "Should we, should we, should we.");
        writer.close();
    
public voidtestBooleanQueryWithSpanQueries()
Tests two span queries.

throws
IOException


        doTestBooleanQueryWithSpanQueries(0.73500174f);
    
public voidtestMultipleDifferentSpanQueries()
Tests a single span query that matches multiple documents.

throws
IOException


        final Query spanQuery1 = new SpanTermQuery(new Term(FIELD_TEXT, "should"));
        final Query spanQuery2 = new SpanTermQuery(new Term(FIELD_TEXT, "we"));
        final BooleanQuery query = new BooleanQuery();
        query.add(spanQuery1, BooleanClause.Occur.MUST);
        query.add(spanQuery2, BooleanClause.Occur.MUST);
        final Hits hits = executeQuery(query);
        final String[] expectedIds = new String[] { "A", "D" };
        final float[] expectedScores = new float[] { 0.93163157f, 0.20698164f };
        assertHits(hits, "multiple different span queries", expectedIds, expectedScores);
    
public voidtestSingleSpanQuery()
Tests a single span query that matches multiple documents.

throws
IOException


        final Query spanQuery = new SpanTermQuery(new Term(FIELD_TEXT, "should"));
        final Hits hits = executeQuery(spanQuery);
        final String[] expectedIds = new String[] { "B", "D", "1", "2", "3", "4", "A" };
        final float[] expectedScores = new float[] { 0.625f, 0.45927936f, 0.35355338f, 0.35355338f, 0.35355338f,
                0.35355338f, 0.26516503f, };
        assertHits(hits, "single span query", expectedIds, expectedScores);
    
public voidtestVerifyIndex()
Verifies that the index has the correct number of documents.

throws
Exception

        final IndexReader reader = IndexReader.open(mDirectory);
        assertEquals(8, reader.numDocs());
        reader.close();