1 package org.apache.lucene.search; 2 3 18 19 import junit.framework.TestCase; 20 21 import org.apache.lucene.index.Term; 22 import org.apache.lucene.index.IndexWriter; 23 import org.apache.lucene.index.IndexReader; 24 import org.apache.lucene.search.IndexSearcher; 25 import org.apache.lucene.store.RAMDirectory; 26 import org.apache.lucene.analysis.SimpleAnalyzer; 27 import org.apache.lucene.document.Document; 28 import org.apache.lucene.document.Field; 29 30 35 public class TestSetNorm extends TestCase { 36 public TestSetNorm(String name) { 37 super(name); 38 } 39 40 public void testSetNorm() throws Exception { 41 RAMDirectory store = new RAMDirectory(); 42 IndexWriter writer = new IndexWriter(store, new SimpleAnalyzer(), true); 43 44 Field f1 = Field.Text("field", "word"); 46 Document d1 = new Document(); 47 d1.add(f1); 48 writer.addDocument(d1); 49 writer.addDocument(d1); 50 writer.addDocument(d1); 51 writer.addDocument(d1); 52 writer.close(); 53 54 IndexReader reader = IndexReader.open(store); 56 reader.setNorm(0, "field", 1.0f); 57 reader.setNorm(1, "field", 2.0f); 58 reader.setNorm(2, "field", 4.0f); 59 reader.setNorm(3, "field", 16.0f); 60 reader.close(); 61 62 final float[] scores = new float[4]; 64 65 new IndexSearcher(store).search 66 (new TermQuery(new Term("field", "word")), 67 new HitCollector() { 68 public final void collect(int doc, float score) { 69 scores[doc] = score; 70 } 71 }); 72 73 float lastScore = 0.0f; 74 75 for (int i = 0; i < 4; i++) { 76 assertTrue(scores[i] > lastScore); 77 lastScore = scores[i]; 78 } 79 } 80 } 81 | Popular Tags |