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_r361370892
##########
File path:
lucene/highlighter/src/java/org/apache/lucene/search/uhighlight/LengthGoalBreakIterator.java
##########
@@ -33,23 +33,32 @@
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) {
- return new LengthGoalBreakIterator(baseIter, minLength, true);
+ public static LengthGoalBreakIterator createMinLength(BreakIterator
baseIter, int minLength,
+ float
fragmentAlignment) {
+ return new LengthGoalBreakIterator(baseIter, minLength,
fragmentAlignment,true);
}
/** 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) {
- return new LengthGoalBreakIterator(baseIter, targetLength, false);
+ public static LengthGoalBreakIterator createClosestToLength(BreakIterator
baseIter, int targetLength,
+ float
fragmentAlignment) {
+ return new LengthGoalBreakIterator(baseIter, targetLength,
fragmentAlignment, false);
}
- private LengthGoalBreakIterator(BreakIterator baseIter, int lengthGoal,
boolean isMinimumLength) {
+ private LengthGoalBreakIterator(BreakIterator baseIter, int lengthGoal,
float fragmentAlignment,
+ boolean isMinimumLength) {
this.baseIter = baseIter;
this.lengthGoal = lengthGoal;
+ this.fragmentAlignment = Math.max(Math.min(fragmentAlignment, 1.f), 0.f);
Review comment:
I would prefer an IllegalArgumentException here.
----------------------------------------------------------------
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]