Skip to content
Open
Show file tree
Hide file tree
Changes from all 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 @@ -52,6 +52,11 @@ protected Codec getCodec() {
return codec;
}

@Override
protected boolean indexFakeImpacts() {
return true;
}

/** Make sure the final sub-block(s) are not skipped. */
public void testFinalBlock() throws Exception {
Directory d = newDirectory();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ protected Codec getCodec() {
return TestUtil.alwaysPostingsFormat(new Lucene912RWPostingsFormat());
}

@Override
protected boolean indexFakeImpacts() {
return true;
}

public void testVInt15() throws IOException {
byte[] bytes = new byte[5];
ByteArrayDataOutput out = new ByteArrayDataOutput(bytes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ protected Codec getCodec() {
return codec;
}

@Override
protected boolean indexFakeImpacts() {
return true;
}

/** Make sure the final sub-block(s) are not skipped. */
public void testFinalBlock() throws Exception {
Directory d = newDirectory();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,9 @@ protected boolean isPostingsEnumReuseImplemented() {
protected Codec getCodec() {
return codec;
}

@Override
protected boolean indexFakeImpacts() {
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,10 @@ public void testMergeStability() throws Exception {
public void testPostingsEnumReuse() throws Exception {
assumeTrue("The MockRandom PF randomizes content on the fly, so we can't check it", false);
}

@Override
protected boolean indexFakeImpacts() {
// we don't know if the codec will use fake impls or not, true is the safe value
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
import org.apache.lucene.index.CodecReader;
import org.apache.lucene.index.DirectoryReader;
import org.apache.lucene.index.Fields;
import org.apache.lucene.index.FreqAndNormBuffer;
import org.apache.lucene.index.ImpactsEnum;
import org.apache.lucene.index.IndexOptions;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.IndexWriter;
Expand Down Expand Up @@ -1798,4 +1800,31 @@ public void testDocIDRunEnd() throws Exception {
}
dir.close();
}

protected boolean indexFakeImpacts() {
return false;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we remove this and fix all postings formats that don't pass the test?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That sounds a good idea although my knowledge about them is very shallow, e.g. I am not sure what is the right way to detect that a field has no frequencies.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typically you would check FieldIndex#indexOptions. If the value is DOCS, then frequencies are not indexed.


public void testImpactsNoFreqs() throws Exception {
assumeFalse("We index fake impacts between 9.0 in 9.12", indexFakeImpacts());
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(FREQS);
FreqAndNormBuffer freqAndNormBuffer = impactsEnum.getImpacts().getImpacts(0);
assertEquals(1, freqAndNormBuffer.size);
assertEquals(1, freqAndNormBuffer.freqs[0]);
assertEquals(1L, freqAndNormBuffer.norms[0]);
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,9 @@ protected Codec getCodec() {
protected boolean isPostingsEnumReuseImplemented() {
return false;
}

@Override
protected boolean indexFakeImpacts() {
return true;
}
}
Loading