You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ja...@apache.org on 2026/02/04 00:34:15 UTC

(lucene) 04/04: Fix FVH boost issue (#15442) (#15635)

This is an automated email from the ASF dual-hosted git repository.

jainankitk pushed a commit to branch branch_10x
in repository https://gitbox.apache.org/repos/asf/lucene.git

commit a9d3f4dbd986e021acad145eb23b95c34e507893
Author: yangfeng123456 <10...@users.noreply.github.com>
AuthorDate: Wed Feb 4 08:07:39 2026 +0800

    Fix FVH boost issue (#15442) (#15635)
---
 lucene/CHANGES.txt                                 |  4 ++++
 .../search/vectorhighlight/FieldPhraseList.java    |  1 +
 .../vectorhighlight/TestFieldPhraseList.java       | 24 ++++++++++++++++++++++
 3 files changed, 29 insertions(+)

diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 92d27a3c348..08c51862bf0 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -205,6 +205,10 @@ Optimizations
 
 Bug Fixes
 ---------------------
+* GITHUB#15442: Preserve boost values when merging overlapping phrases in
+  FastVectorHighlighter so highlight scoring fully reflects query boosts.
+  (Yang Feng)
+
 * GITHUB#14161: PointInSetQuery's constructor now throws IllegalArgumentException
   instead of UnsupportedOperationException when values are out of order. (Shubham Sharma)
 
diff --git a/lucene/highlighter/src/java/org/apache/lucene/search/vectorhighlight/FieldPhraseList.java b/lucene/highlighter/src/java/org/apache/lucene/search/vectorhighlight/FieldPhraseList.java
index ae3bd7b0357..63e77b48657 100644
--- a/lucene/highlighter/src/java/org/apache/lucene/search/vectorhighlight/FieldPhraseList.java
+++ b/lucene/highlighter/src/java/org/apache/lucene/search/vectorhighlight/FieldPhraseList.java
@@ -177,6 +177,7 @@ public class FieldPhraseList {
         // The result is that all informations in TermInfo are lost and not available for further
         // operations.
         existWpi.getTermsInfos().addAll(wpi.getTermsInfos());
+        existWpi.boost += wpi.getBoost(); // Accumulate boost
         return;
       }
     }
diff --git a/lucene/highlighter/src/test/org/apache/lucene/search/vectorhighlight/TestFieldPhraseList.java b/lucene/highlighter/src/test/org/apache/lucene/search/vectorhighlight/TestFieldPhraseList.java
index 8396423e37b..f2b76a6e722 100644
--- a/lucene/highlighter/src/test/org/apache/lucene/search/vectorhighlight/TestFieldPhraseList.java
+++ b/lucene/highlighter/src/test/org/apache/lucene/search/vectorhighlight/TestFieldPhraseList.java
@@ -289,4 +289,28 @@ public class TestFieldPhraseList extends AbstractTestCase {
     assertTrue(a.compareTo(b) < 0);
     assertTrue(b.compareTo(a) > 0);
   }
+
+  public void testMergeOverlappingWeightedPhraseInfoAccumulateBoost() {
+    LinkedList<TermInfo> infos1 = new LinkedList<>();
+    infos1.add(new TermInfo("中国", 0, 2, 0, 0));
+    infos1.add(new TermInfo("经济", 3, 5, 1, 1));
+    WeightedPhraseInfo wpi1 = new WeightedPhraseInfo(infos1, 2.0f);
+
+    LinkedList<TermInfo> infos2 = new LinkedList<>();
+    infos2.add(new TermInfo("经济", 3, 5, 1, 1));
+    infos2.add(new TermInfo("发展", 6, 8, 2, 2));
+    WeightedPhraseInfo wpi2 = new WeightedPhraseInfo(infos2, 3.0f);
+
+    FieldPhraseList fpl = new FieldPhraseList(new FieldPhraseList[0]);
+    fpl.getPhraseList().add(wpi1);
+
+    // This will execute: existWpi.boost += wpi.getBoost();
+    fpl.addIfNoOverlap(wpi2);
+
+    assertEquals(1, fpl.getPhraseList().size());
+
+    WeightedPhraseInfo merged = fpl.getPhraseList().get(0);
+
+    assertEquals(5.0f, merged.getBoost(), 0.0001f);
+  }
 }