Clover Coverage Report
Coverage timestamp: Fri May 9 2008 10:54:27 EST
29   80   4   9.67
2   48   0.14   3
3     1.33  
1    
 
  TestDocBoost       Line # 31 29 4 100% 1.0
 
  (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 junit.framework.TestCase;
20    import org.apache.lucene.analysis.SimpleAnalyzer;
21    import org.apache.lucene.document.*;
22    import org.apache.lucene.index.IndexWriter;
23    import org.apache.lucene.index.Term;
24    import org.apache.lucene.store.RAMDirectory;
25   
26    /** Document boost unit test.
27    *
28    * @author Doug Cutting
29    * @version $Revision: 413201 $
30    */
 
31    public class TestDocBoost extends TestCase {
 
32  1 toggle public TestDocBoost(String name) {
33  1 super(name);
34    }
35   
 
36  1 toggle public void testDocBoost() throws Exception {
37  1 RAMDirectory store = new RAMDirectory();
38  1 IndexWriter writer = new IndexWriter(store, new SimpleAnalyzer(), true);
39   
40  1 Fieldable f1 = new Field("field", "word", Field.Store.YES, Field.Index.TOKENIZED);
41  1 Fieldable f2 = new Field("field", "word", Field.Store.YES, Field.Index.TOKENIZED);
42  1 f2.setBoost(2.0f);
43   
44  1 Document d1 = new Document();
45  1 Document d2 = new Document();
46  1 Document d3 = new Document();
47  1 Document d4 = new Document();
48  1 d3.setBoost(3.0f);
49  1 d4.setBoost(2.0f);
50   
51  1 d1.add(f1); // boost = 1
52  1 d2.add(f2); // boost = 2
53  1 d3.add(f1); // boost = 3
54  1 d4.add(f2); // boost = 4
55   
56  1 writer.addDocument(d1);
57  1 writer.addDocument(d2);
58  1 writer.addDocument(d3);
59  1 writer.addDocument(d4);
60  1 writer.optimize();
61  1 writer.close();
62   
63  1 final float[] scores = new float[4];
64   
65  1 new IndexSearcher(store).search
66    (new TermQuery(new Term("field", "word")),
67    new HitCollector() {
 
68  4 toggle public final void collect(int doc, float score) {
69  4 scores[doc] = score;
70    }
71    });
72   
73  1 float lastScore = 0.0f;
74   
75  5 for (int i = 0; i < 4; i++) {
76  4 assertTrue(scores[i] > lastScore);
77  4 lastScore = scores[i];
78    }
79    }
80    }