Apache Lucene open-source search software
Provide better impacts for fields indexed with IndexOptions.DOCS (#14511)
expani1729d05d6fe173f8
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txtindex 47f91c3ba7c..0a64dce99f4 100644--- a/lucene/CHANGES.txt+++ b/lucene/CHANGES.txt@@ -114,6 +114,8 @@ Bug Fixes* GITHUB#14523, GITHUB#14530: Correct TermOrdValComparator competitive iterator so that it forces sparsefield iteration to be at least scoring window baseline when doing intoBitSet. (Ben Trent, Adrien Grand)+* GITHUB#14445: Provide better impacts for fields indexed with IndexOptions.DOCS GITHUB#14511 (Aniketh Jain)+* GITHUB#14543: Fixed lead cost computations for bulk scorers of conjunctivequeries that mix MUST and FILTER clauses, and disjunctive queries thatconfigure a minimum number of matching SHOULD clauses.diff --git a/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/lucene101/Lucene101PostingsReader.java b/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/lucene101/Lucene101PostingsReader.javaindex f9a599821a7..d45a079ec32 100644--- a/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/lucene101/Lucene101PostingsReader.java+++ b/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/lucene101/Lucene101PostingsReader.java@@ -70,6 +70,10 @@ public final class Lucene101PostingsReader extends PostingsReaderBase {private static final List<Impact> DUMMY_IMPACTS =Collections.singletonList(new Impact(Integer.MAX_VALUE, 1L));+ // We stopped storing a placeholder impact with freq=1 for fields with DOCS after 9.12.0+ private static final List<Impact> DUMMY_IMPACTS_NO_FREQS =+ Collections.singletonList(new Impact(1, 1L));+private final IndexInput docIn;private final IndexInput posIn;private final IndexInput payIn;@@ -1325,13 +1329,14 @@ public final class Lucene101PostingsReader extends PostingsReaderBase {@Overridepublic List<Impact> getImpacts(int level) {- if (indexHasFreq) {- if (level == 0 && level0LastDocID != NO_MORE_DOCS) {- return readImpacts(level0SerializedImpacts, level0Impacts);- }- if (level == 1) {- return readImpacts(level1SerializedImpacts, level1Impacts);- }+ if (indexHasFreq == false) {+ return DUMMY_IMPACTS_NO_FREQS;+ }+ if (level == 0 && level0LastDocID != NO_MORE_DOCS) {+ return readImpacts(level0SerializedImpacts, level0Impacts);+ }+ if (level == 1) {+ return readImpacts(level1SerializedImpacts, level1Impacts);}return DUMMY_IMPACTS;}diff --git a/lucene/core/src/java/org/apache/lucene/codecs/lucene103/Lucene103PostingsReader.java b/lucene/core/src/java/org/apache/lucene/codecs/lucene103/Lucene103PostingsReader.javaindex ccacfc4658a..291830f5126 100644--- a/lucene/core/src/java/org/apache/lucene/codecs/lucene103/Lucene103PostingsReader.java+++ b/lucene/core/src/java/org/apache/lucene/codecs/lucene103/Lucene103PostingsReader.java@@ -73,6 +73,10 @@ public final class Lucene103PostingsReader extends PostingsReaderBase {private static final List<Impact> DUMMY_IMPACTS =Collections.singletonList(new Impact(Integer.MAX_VALUE, 1L));+ // We stopped storing a placeholder impact with freq=1 for fields with DOCS after 9.12.0+ private static final List<Impact> DUMMY_IMPACTS_NO_FREQS =+ Collections.singletonList(new Impact(1, 1L));+private final IndexInput docIn;private final IndexInput posIn;private final IndexInput payIn;@@ -1302,13 +1306,14 @@ public final class Lucene103PostingsReader extends PostingsReaderBase {@Overridepublic List<Impact> getImpacts(int level) {- if (indexHasFreq) {- if (level == 0 && level0LastDocID != NO_MORE_DOCS) {- return readImpacts(level0SerializedImpacts, level0Impacts);- }- if (level == 1) {- return readImpacts(level1SerializedImpacts, level1Impacts);- }+ if (indexHasFreq == false) {+ return DUMMY_IMPACTS_NO_FREQS;+ }+ if (level == 0 && level0LastDocID != NO_MORE_DOCS) {+ return readImpacts(level0SerializedImpacts, level0Impacts);+ }+ if (level == 1) {+ return readImpacts(level1SerializedImpacts, level1Impacts);}return DUMMY_IMPACTS;}