| 1 |
|
package org.apache.lucene.search; |
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 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 |
|
|
| 28 |
|
|
| 29 |
|
@author |
| 30 |
|
@version |
| 31 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (29) |
Complexity: 4 |
Complexity Density: 0.17 |
|
| 32 |
|
public class TestSetNorm extends TestCase { |
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 33 |
1
|
public TestSetNorm(String name) {... |
| 34 |
1
|
super(name); |
| 35 |
|
} |
| 36 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (24) |
Complexity: 2 |
Complexity Density: 0.09 |
1
PASS
|
|
| 37 |
1
|
public void testSetNorm() throws Exception {... |
| 38 |
1
|
RAMDirectory store = new RAMDirectory(); |
| 39 |
1
|
IndexWriter writer = new IndexWriter(store, new SimpleAnalyzer(), true); |
| 40 |
|
|
| 41 |
|
|
| 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 |
|
|
| 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 |
|
|
| 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() { |
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 65 |
4
|
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 |
|
} |