sunny6142 commented on code in PR #15434:
URL: https://github.com/apache/lucene/pull/15434#discussion_r2541283314


##########
lucene/highlighter/src/java/org/apache/lucene/search/vectorhighlight/FieldQuery.java:
##########
@@ -429,7 +429,7 @@ private void markTerminal(float boost) {
     private void markTerminal(int slop, float boost) {
       this.terminal = true;
       this.slop = slop;
-      this.boost = boost;
+      this.boost = Math.max(this.boost, boost);

Review Comment:
   Your approach seems simpler, but I think we have an opportunity to optimize 
this. Instead of always executing all assignments, should we have something 
like:
   
   ```
      if (!this.terminal || boost > this.boost) {
           this.terminal = true;
           this.slop = slop;
           this.boost = boost;
           this.termOrPhraseNumber = fieldQuery.nextTermOrPhraseNumber();
         }
   ```
   
   **Benefits:**
   
   Performance: Avoids unnecessary state updates when boost doesn't improve
   
   Semantic correctness: termOrPhraseNumber only increments when meaningful 
changes occur
   
   Cleaner logic: Single condition handles both initialization and duplicate 
prevention
   
   **Current approach with Math.max():**
   
   Always updates all fields, even when boost=1 < existing boost=100
   
   Increments termOrPhraseNumber unnecessarily on duplicate calls
   
   **Proposed approach:**
   
   Only updates when first call (!this.terminal) or when boost improves (boost 
> this.boost)
   
   More efficient for queries with many overlapping phrases
   
   **What do you think?**



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to