Clover Coverage Report
Coverage timestamp: Fri May 9 2008 10:54:27 EST
24   77   4   8
2   44   0.17   3
3     1.33  
1    
 
  TestSetNorm       Line # 32 24 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.IndexReader;
23    import org.apache.lucene.index.IndexWriter;
24    import org.apache.lucene.index.Term;
25    import org.apache.lucene.store.RAMDirectory;
26   
27    /** Document boost unit test.
28    *
29    * @author Doug Cutting
30    * @version $Revision: 413201 $
31    */
 
32    public class TestSetNorm extends TestCase {
 
33  1 toggle public TestSetNorm(String name) {
34  1 super(name);
35    }
36   
 
37  1 toggle public void testSetNorm() throws Exception {
38  1 RAMDirectory store = new RAMDirectory();
39  1 IndexWriter writer = new IndexWriter(store, new SimpleAnalyzer(), true);
40   
41    // add the same document four times
42  1 Fieldable f1 = new Field("field", "word", Field.Store.YES, Field.Index.TOKENIZED);
43  1 Document d1 = new Document();
44  1 d1.add(f1);
45  1 writer.addDocument(d1);
46  1 writer.addDocument(d1);
47  1 writer.addDocument(d1);
48  1 writer.addDocument(d1);
49  1 writer.close();
50   
51    // reset the boost of each instance of this document
52  1 IndexReader reader = IndexReader.open(store);
53  1 reader.setNorm(0, "field", 1.0f);
54  1 reader.setNorm(1, "field", 2.0f);
55  1 reader.setNorm(2, "field", 4.0f);
56  1 reader.setNorm(3, "field", 16.0f);
57  1 reader.close();
58   
59    // check that searches are ordered by this boost
60  1 final float[] scores = new float[4];
61   
62  1 new IndexSearcher(store).search
63    (new TermQuery(new Term("field", "word")),
64    new HitCollector() {
 
65  4 toggle public final void collect(int doc, float score) {
66  4 scores[doc] = score;
67    }
68    });
69   
70  1 float lastScore = 0.0f;
71   
72  5 for (int i = 0; i < 4; i++) {
73  4 assertTrue(scores[i] > lastScore);
74  4 lastScore = scores[i];
75    }
76    }
77    }