dsmiley commented on a change in pull request #1123: LUCENE-9093: Unified
highlighter with word separator never gives context to the left
URL: https://github.com/apache/lucene-solr/pull/1123#discussion_r361482118
##########
File path:
lucene/highlighter/src/java/org/apache/lucene/search/uhighlight/LengthGoalBreakIterator.java
##########
@@ -33,23 +33,45 @@
private final BreakIterator baseIter;
private final int lengthGoal;
+ private final float fragmentAlignment; // how much text to align before
match-fragment, valid in range [0, 1]
private final boolean isMinimumLength; // if false then is "closest to"
length
+ private int fragmentEndFromPreceding; // store the match-break end for reuse
in following()
+ private int fragmentEndFollowingLengthGoalFromPreceding; // store the
remaining length to collect in following()
/** Breaks will be at least {@code minLength} apart (to the extent
possible). */
+ public static LengthGoalBreakIterator createMinLength(BreakIterator
baseIter, int minLength,
+ float
fragmentAlignment) {
+ return new LengthGoalBreakIterator(baseIter, minLength,
fragmentAlignment,true);
+ }
+
+ /** For backwards compatibility you can initialise the break iterator
without fragmentAlignment. */
public static LengthGoalBreakIterator createMinLength(BreakIterator
baseIter, int minLength) {
- return new LengthGoalBreakIterator(baseIter, minLength, true);
+ return createMinLength(baseIter, minLength, 0.f);
}
/** Breaks will be on average {@code targetLength} apart; the closest break
to this target (before or after)
* is chosen. */
+ public static LengthGoalBreakIterator createClosestToLength(BreakIterator
baseIter, int targetLength,
+ float
fragmentAlignment) {
+ return new LengthGoalBreakIterator(baseIter, targetLength,
fragmentAlignment, false);
+ }
+
+ /** For backwards compatibility you can initialise the break iterator
without fragmentAlignment. */
public static LengthGoalBreakIterator createClosestToLength(BreakIterator
baseIter, int targetLength) {
- return new LengthGoalBreakIterator(baseIter, targetLength, false);
+ return createClosestToLength(baseIter, targetLength, 0.f);
}
- private LengthGoalBreakIterator(BreakIterator baseIter, int lengthGoal,
boolean isMinimumLength) {
+ private LengthGoalBreakIterator(BreakIterator baseIter, int lengthGoal,
float fragmentAlignment,
+ boolean isMinimumLength) {
this.baseIter = baseIter;
this.lengthGoal = lengthGoal;
+ if (fragmentAlignment < 0.f || fragmentAlignment > 1.f ||
!Float.isFinite(fragmentAlignment)) {
+ throw new IllegalArgumentException("fragmentAlignment must be >= zero
and <= one");
+ }
+ this.fragmentAlignment = Math.max(Math.min(fragmentAlignment, 1.f), 0.f);
Review comment:
Why the max & min at this point?
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]