From fb8338700269b11bfc3982935d5791a41cba0ec3 Mon Sep 17 00:00:00 2001 From: Greg Miller Date: Wed, 30 Mar 2022 09:36:05 -0700 Subject: [PATCH] LUCENE-10491: Fix correctness bug in TaxonomyFacetSumValueSource score providing (#775) --- lucene/CHANGES.txt | 3 +++ .../lucene/facet/taxonomy/TaxonomyFacetSumValueSource.java | 2 +- .../facet/taxonomy/TestTaxonomyFacetSumValueSource.java | 7 ++++++- 3 files changed, 10 insertions(+), 2 deletions(-) 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));