Clover Coverage Report
Coverage timestamp: Fri May 9 2008 10:54:27 EST
20   77   4   10
2   41   0.2   2
2     2  
1    
 
  TestBooleanScorer       Line # 34 20 4 95.8% 0.9583333
 
  (1)
 
1    package org.apache.lucene.search;
2   
3    /**
4    * Copyright 2004 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.WhitespaceAnalyzer;
22    import org.apache.lucene.document.Document;
23    import org.apache.lucene.document.Field;
24    import org.apache.lucene.index.IndexWriter;
25    import org.apache.lucene.index.Term;
26    import org.apache.lucene.store.RAMDirectory;
27   
28    import junit.framework.TestCase;
29   
30    /**
31    * @author Christoph Goller
32    * @version $rcs = ' $Id: TestBooleanScorer.java 150700 2004-12-10 19:36:40Z goller $ ' ;
33    */
 
34    public class TestBooleanScorer extends TestCase
35    {
36   
 
37  1 toggle public TestBooleanScorer(String name) {
38  1 super(name);
39    }
40   
41    private static final String FIELD = "category";
42   
 
43  1 toggle public void testMethod() {
44  1 RAMDirectory directory = new RAMDirectory();
45   
46  1 String[] values = new String[] { "1", "2", "3", "4" };
47   
48  1 try {
49  1 IndexWriter writer = new IndexWriter(directory, new WhitespaceAnalyzer(), true);
50  5 for (int i = 0; i < values.length; i++) {
51  4 Document doc = new Document();
52  4 doc.add(new Field(FIELD, values[i], Field.Store.YES, Field.Index.UN_TOKENIZED));
53  4 writer.addDocument(doc);
54    }
55  1 writer.close();
56   
57  1 BooleanQuery booleanQuery1 = new BooleanQuery();
58  1 booleanQuery1.add(new TermQuery(new Term(FIELD, "1")), BooleanClause.Occur.SHOULD);
59  1 booleanQuery1.add(new TermQuery(new Term(FIELD, "2")), BooleanClause.Occur.SHOULD);
60   
61  1 BooleanQuery query = new BooleanQuery();
62  1 query.add(booleanQuery1, BooleanClause.Occur.MUST);
63  1 query.add(new TermQuery(new Term(FIELD, "9")), BooleanClause.Occur.MUST_NOT);
64   
65  1 IndexSearcher indexSearcher = new IndexSearcher(directory);
66  1 Hits hits = indexSearcher.search(query);
67  1 assertEquals("Number of matched documents", 2, hits.length());
68   
69    }
70    catch (IOException e) {
71  0 fail(e.getMessage());
72    }
73   
74    }
75   
76   
77    }