Clover Coverage Report
Coverage timestamp: Fri May 9 2008 10:54:27 EST
24   106   5   4.8
0   45   0.21   5
5     1  
1    
 
  TestSpansAdvanced2       Line # 33 24 5 100% 1.0
 
  (4)
 
1    package org.apache.lucene.search.spans;
2   
3    /**
4    * Copyright 2005 The Apache Software Foundation
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10    * http://www.apache.org/licenses/LICENSE-2.0
11    *
12    * Unless required by applicable law or agreed to in writing, software
13    * distributed under the License is distributed on an "AS IS" BASIS,
14    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15    * See the License for the specific language governing permissions and
16    * limitations under the License.
17    */
18   
19    import java.io.IOException;
20   
21    import org.apache.lucene.analysis.standard.StandardAnalyzer;
22    import org.apache.lucene.index.IndexReader;
23    import org.apache.lucene.index.IndexWriter;
24    import org.apache.lucene.index.Term;
25    import org.apache.lucene.search.*;
26   
27    /*******************************************************************************
28    * Some expanded tests to make sure my patch doesn't break other SpanTermQuery
29    * functionality.
30    *
31    * @author Reece Wilton
32    */
 
33    public class TestSpansAdvanced2 extends TestSpansAdvanced {
34    IndexSearcher searcher2;
35    /**
36    * Initializes the tests by adding documents to the index.
37    */
 
38  4 toggle protected void setUp() throws Exception {
39  4 super.setUp();
40   
41    // create test index
42  4 final IndexWriter writer = new IndexWriter(mDirectory, new StandardAnalyzer(), false);
43  4 addDocument(writer, "A", "Should we, could we, would we?");
44  4 addDocument(writer, "B", "It should. Should it?");
45  4 addDocument(writer, "C", "It shouldn't.");
46  4 addDocument(writer, "D", "Should we, should we, should we.");
47  4 writer.close();
48   
49    // re-open the searcher since we added more docs
50  4 searcher2 = new IndexSearcher(mDirectory);
51    }
52   
53    /**
54    * Verifies that the index has the correct number of documents.
55    *
56    * @throws Exception
57    */
 
58  1 toggle public void testVerifyIndex() throws Exception {
59  1 final IndexReader reader = IndexReader.open(mDirectory);
60  1 assertEquals(8, reader.numDocs());
61  1 reader.close();
62    }
63   
64    /**
65    * Tests a single span query that matches multiple documents.
66    *
67    * @throws IOException
68    */
 
69  1 toggle public void testSingleSpanQuery() throws IOException {
70   
71  1 final Query spanQuery = new SpanTermQuery(new Term(FIELD_TEXT, "should"));
72  1 final String[] expectedIds = new String[] { "B", "D", "1", "2", "3", "4", "A" };
73  1 final float[] expectedScores = new float[] { 0.625f, 0.45927936f, 0.35355338f, 0.35355338f, 0.35355338f,
74    0.35355338f, 0.26516503f, };
75  1 assertHits(searcher2, spanQuery, "single span query", expectedIds, expectedScores);
76    }
77   
78    /**
79    * Tests a single span query that matches multiple documents.
80    *
81    * @throws IOException
82    */
 
83  1 toggle public void testMultipleDifferentSpanQueries() throws IOException {
84   
85  1 final Query spanQuery1 = new SpanTermQuery(new Term(FIELD_TEXT, "should"));
86  1 final Query spanQuery2 = new SpanTermQuery(new Term(FIELD_TEXT, "we"));
87  1 final BooleanQuery query = new BooleanQuery();
88  1 query.add(spanQuery1, BooleanClause.Occur.MUST);
89  1 query.add(spanQuery2, BooleanClause.Occur.MUST);
90  1 final String[] expectedIds = new String[] { "D", "A" };
91    // these values were pre LUCENE-413
92    // final float[] expectedScores = new float[] { 0.93163157f, 0.20698164f };
93  1 final float[] expectedScores = new float[] { 1.0191123f, 0.93163157f };
94  1 assertHits(searcher2, query, "multiple different span queries", expectedIds, expectedScores);
95    }
96   
97    /**
98    * Tests two span queries.
99    *
100    * @throws IOException
101    */
 
102  1 toggle public void testBooleanQueryWithSpanQueries() throws IOException {
103   
104  1 doTestBooleanQueryWithSpanQueries(searcher2, 0.73500174f);
105    }
106    }