|
29 | 29 | import org.apache.lucene.document.Field; |
30 | 30 | import org.apache.lucene.index.DirectoryReader; |
31 | 31 | import org.apache.lucene.index.Impact; |
| 32 | +import org.apache.lucene.index.ImpactsEnum; |
32 | 33 | import org.apache.lucene.index.IndexWriter; |
33 | 34 | import org.apache.lucene.index.IndexWriterConfig; |
| 35 | +import org.apache.lucene.index.LeafReader; |
| 36 | +import org.apache.lucene.index.PostingsEnum; |
| 37 | +import org.apache.lucene.index.TermsEnum; |
34 | 38 | import org.apache.lucene.store.ByteArrayDataInput; |
35 | 39 | import org.apache.lucene.store.ByteArrayDataOutput; |
36 | 40 | import org.apache.lucene.store.Directory; |
|
39 | 43 | import org.apache.lucene.store.IndexOutput; |
40 | 44 | import org.apache.lucene.tests.analysis.MockAnalyzer; |
41 | 45 | import org.apache.lucene.tests.index.BasePostingsFormatTestCase; |
| 46 | +import org.apache.lucene.tests.index.RandomIndexWriter; |
42 | 47 | import org.apache.lucene.tests.util.TestUtil; |
| 48 | +import org.apache.lucene.util.BytesRef; |
43 | 49 |
|
44 | 50 | public class TestLucene103PostingsFormat extends BasePostingsFormatTestCase { |
45 | 51 |
|
@@ -154,4 +160,26 @@ private void doTestImpactSerialization(List<Impact> impacts) throws IOException |
154 | 160 | } |
155 | 161 | } |
156 | 162 | } |
| 163 | + |
| 164 | + public void testImpactsNoFreqs() throws Exception { |
| 165 | + try (Directory dir = newDirectory()) { |
| 166 | + IndexWriterConfig iwc = newIndexWriterConfig(new MockAnalyzer(random())); |
| 167 | + iwc.setCodec(getCodec()); |
| 168 | + try (RandomIndexWriter iw = new RandomIndexWriter(random(), dir, iwc)) { |
| 169 | + Document doc = new Document(); |
| 170 | + doc.add(newStringField("field", "value", Field.Store.NO)); |
| 171 | + iw.addDocument(doc); |
| 172 | + try (DirectoryReader ir = iw.getReader()) { |
| 173 | + LeafReader ar = getOnlyLeafReader(ir); |
| 174 | + TermsEnum termsEnum = ar.terms("field").iterator(); |
| 175 | + termsEnum.seekExact(new BytesRef("value")); |
| 176 | + ImpactsEnum impactsEnum = termsEnum.impacts(PostingsEnum.FREQS); |
| 177 | + List<Impact> impacts = impactsEnum.getImpacts().getImpacts(0); |
| 178 | + assertEquals(1, impacts.size()); |
| 179 | + assertEquals(1, impacts.get(0).freq); |
| 180 | + assertEquals(1L, impacts.get(0).norm); |
| 181 | + } |
| 182 | + } |
| 183 | + } |
| 184 | + } |
157 | 185 | } |
0 commit comments