Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ public final class Lucene103PostingsReader extends PostingsReaderBase {
// less than 128 docs left to evaluate anyway.
private static final List<Impact> DUMMY_IMPACTS =
Collections.singletonList(new Impact(Integer.MAX_VALUE, 1L));
// impacts when there is no frequency, max frequency is 1.
private static final List<Impact> IMPACTS_NO_FREQ = Collections.singletonList(new Impact(1, 1L));

private final IndexInput docIn;
private final IndexInput posIn;
Expand Down Expand Up @@ -1381,8 +1383,9 @@ public List<Impact> getImpacts(int level) {
if (level == 1) {
return readImpacts(level1SerializedImpacts, level1Impacts);
}
return DUMMY_IMPACTS;
}
return DUMMY_IMPACTS;
return IMPACTS_NO_FREQ;
}

private List<Impact> readImpacts(BytesRef serialized, MutableImpactList impactsList) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,12 @@
import org.apache.lucene.document.Field;
import org.apache.lucene.index.DirectoryReader;
import org.apache.lucene.index.Impact;
import org.apache.lucene.index.ImpactsEnum;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.IndexWriterConfig;
import org.apache.lucene.index.LeafReader;
import org.apache.lucene.index.PostingsEnum;
import org.apache.lucene.index.TermsEnum;
import org.apache.lucene.store.ByteArrayDataInput;
import org.apache.lucene.store.ByteArrayDataOutput;
import org.apache.lucene.store.Directory;
Expand All @@ -39,7 +43,9 @@
import org.apache.lucene.store.IndexOutput;
import org.apache.lucene.tests.analysis.MockAnalyzer;
import org.apache.lucene.tests.index.BasePostingsFormatTestCase;
import org.apache.lucene.tests.index.RandomIndexWriter;
import org.apache.lucene.tests.util.TestUtil;
import org.apache.lucene.util.BytesRef;

public class TestLucene103PostingsFormat extends BasePostingsFormatTestCase {

Expand Down Expand Up @@ -154,4 +160,26 @@ private void doTestImpactSerialization(List<Impact> impacts) throws IOException
}
}
}

public void testImpactsNoFreqs() throws Exception {
try (Directory dir = newDirectory()) {
IndexWriterConfig iwc = newIndexWriterConfig(new MockAnalyzer(random()));
iwc.setCodec(getCodec());
try (RandomIndexWriter iw = new RandomIndexWriter(random(), dir, iwc)) {
Document doc = new Document();
doc.add(newStringField("field", "value", Field.Store.NO));
iw.addDocument(doc);
try (DirectoryReader ir = iw.getReader()) {
LeafReader ar = getOnlyLeafReader(ir);
TermsEnum termsEnum = ar.terms("field").iterator();
termsEnum.seekExact(new BytesRef("value"));
ImpactsEnum impactsEnum = termsEnum.impacts(PostingsEnum.FREQS);
List<Impact> impacts = impactsEnum.getImpacts().getImpacts(0);
assertEquals(1, impacts.size());
assertEquals(1, impacts.get(0).freq);
assertEquals(1L, impacts.get(0).norm);
}
}
}
}
}