Skip to content

Apache Lucene open-source search software

LUCENE-10491: Fix correctness bug in TaxonomyFacetSumValueSource score providing (#775)

Greg Millerfb8338700269
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index e59fa96d290..9baf6468f88 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -93,6 +93,9 @@ Bug Fixes
* LUCENE-10477: Highlighter: WeightedSpanTermExtractor.extractWeightedSpanTerms to Query#rewrite
multiple times if necessary. (Christine Poerschke, Adrien Grand)
+* LUCENE-10491: A correctness bug in the way scores are provided within TaxonomyFacetSumValueSource
+ was fixed. (Michael McCandless, Greg Miller)
+
Build
---------------------
diff --git a/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/TaxonomyFacetSumValueSource.java b/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/TaxonomyFacetSumValueSource.java
index 976eb9f953e..95c9301e0f0 100644
--- a/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/TaxonomyFacetSumValueSource.java
+++ b/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/TaxonomyFacetSumValueSource.java
@@ -75,7 +75,7 @@ public class TaxonomyFacetSumValueSource extends FloatTaxonomyFacets {
@Override
public boolean advanceExact(int doc) throws IOException {
- index++;
+ index = doc;
return true;
}
};
diff --git a/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/TestTaxonomyFacetSumValueSource.java b/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/TestTaxonomyFacetSumValueSource.java
index cdb624b1cd6..53630a85dd2 100644
--- a/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/TestTaxonomyFacetSumValueSource.java
+++ b/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/TestTaxonomyFacetSumValueSource.java
@@ -353,8 +353,13 @@ public class TestTaxonomyFacetSumValueSource extends FacetTestCase {
IndexWriter iw = new IndexWriter(indexDir, newIndexWriterConfig(new MockAnalyzer(random())));
FacetsConfig config = new FacetsConfig();
+
+ // Add a doc without the price field to exercise the bug found in LUCENE-10491:
+ Document doc = new Document();
+ iw.addDocument(config.build(taxoWriter, doc));
+
for (int i = 0; i < 4; i++) {
- Document doc = new Document();
+ doc = new Document();
doc.add(new NumericDocValuesField("price", (i + 1)));
doc.add(new FacetField("a", Integer.toString(i % 2)));
iw.addDocument(config.build(taxoWriter, doc));