Skip to content
Merged
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
4 changes: 3 additions & 1 deletion lucene/CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ http://s.apache.org/luceneversions

Bug Fixes
---------------------
(No changes)
* GITHUB#15263: Fix the returned Impact returned from Lucene103PostingsReader when frequencies
are not indexed. It was returning a wrong frequency in that case affecting scoring which
might led to performance issues. (Ignacio Vera)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: maybe replace "wrong" with "suboptimal" since it's correct to return impact scores that are much higher than they should, just suboptimal as it hurts dynamic pruning?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done in 25d6374


======================= Lucene 10.3.0 =======================

Expand Down
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);
}
}
}
}
}