Clover Coverage Report
Coverage timestamp: Fri May 9 2008 10:54:27 EST
91   224   26   5.69
20   150   0.29   8
16     1.62  
2    
 
  TestBoolean2       Line # 40 91 26 98.4% 0.984252
  TestBoolean2.Callback       Line # 194 0 0 - -1.0
 
  (12)
 
1    package org.apache.lucene.search;
2   
3    /**
4    * Copyright 2005 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   
20    import org.apache.lucene.store.RAMDirectory;
21   
22    import org.apache.lucene.index.IndexWriter;
23    import org.apache.lucene.index.Term;
24   
25    import org.apache.lucene.analysis.WhitespaceAnalyzer;
26   
27    import org.apache.lucene.document.Document;
28    import org.apache.lucene.document.Field;
29   
30    import org.apache.lucene.queryParser.QueryParser;
31    import org.apache.lucene.queryParser.ParseException;
32   
33    import junit.framework.TestCase;
34   
35    import java.util.Random;
36   
37    /** Test BooleanQuery2 against BooleanQuery by overriding the standard query parser.
38    * This also tests the scoring order of BooleanQuery.
39    */
 
40    public class TestBoolean2 extends TestCase {
41    private IndexSearcher searcher;
42   
43    public static final String field = "field";
44   
 
45  11 toggle public void setUp() throws Exception {
46  11 RAMDirectory directory = new RAMDirectory();
47  11 IndexWriter writer= new IndexWriter(directory, new WhitespaceAnalyzer(), true);
48  55 for (int i = 0; i < docFields.length; i++) {
49  44 Document doc = new Document();
50  44 doc.add(new Field(field, docFields[i], Field.Store.NO, Field.Index.TOKENIZED));
51  44 writer.addDocument(doc);
52    }
53  11 writer.close();
54  11 searcher = new IndexSearcher(directory);
55    }
56   
57    private String[] docFields = {
58    "w1 w2 w3 w4 w5",
59    "w1 w3 w2 w3",
60    "w1 xx w2 yy w3",
61    "w1 w3 xx w2 yy w3"
62    };
63   
 
64  20 toggle public Query makeQuery(String queryText) throws ParseException {
65  20 Query q = (new QueryParser(field, new WhitespaceAnalyzer())).parse(queryText);
66  20 return q;
67    }
68   
 
69  10 toggle public void queriesTest(String queryText, int[] expDocNrs) throws Exception {
70    //System.out.println();
71    //System.out.println("Query: " + queryText);
72  10 try {
73  10 Query query1 = makeQuery(queryText);
74  10 BooleanQuery.setUseScorer14(true);
75  10 Hits hits1 = searcher.search(query1);
76   
77  10 Query query2 = makeQuery(queryText); // there should be no need to parse again...
78  10 BooleanQuery.setUseScorer14(false);
79  10 Hits hits2 = searcher.search(query2);
80   
81  10 CheckHits.checkHitsQuery(query2, hits1, hits2, expDocNrs);
82    } finally { // even when a test fails.
83  10 BooleanQuery.setUseScorer14(false);
84    }
85    }
86   
 
87  1 toggle public void testQueries01() throws Exception {
88  1 String queryText = "+w3 +xx";
89  1 int[] expDocNrs = {2,3};
90  1 queriesTest(queryText, expDocNrs);
91    }
92   
 
93  1 toggle public void testQueries02() throws Exception {
94  1 String queryText = "+w3 xx";
95  1 int[] expDocNrs = {2,3,1,0};
96  1 queriesTest(queryText, expDocNrs);
97    }
98   
 
99  1 toggle public void testQueries03() throws Exception {
100  1 String queryText = "w3 xx";
101  1 int[] expDocNrs = {2,3,1,0};
102  1 queriesTest(queryText, expDocNrs);
103    }
104   
 
105  1 toggle public void testQueries04() throws Exception {
106  1 String queryText = "w3 -xx";
107  1 int[] expDocNrs = {1,0};
108  1 queriesTest(queryText, expDocNrs);
109    }
110   
 
111  1 toggle public void testQueries05() throws Exception {
112  1 String queryText = "+w3 -xx";
113  1 int[] expDocNrs = {1,0};
114  1 queriesTest(queryText, expDocNrs);
115    }
116   
 
117  1 toggle public void testQueries06() throws Exception {