Class LengthGoalBreakIterator
- java.lang.Object
-
- java.text.BreakIterator
-
- org.apache.lucene.search.uhighlight.LengthGoalBreakIterator
-
- All Implemented Interfaces:
java.lang.Cloneable
public class LengthGoalBreakIterator extends java.text.BreakIterator
Wraps anotherBreakIterator
to skip past breaks that would result in passages that are too short. It's still possible to get a short passage but only at the very end of the input text.Important: This is not a general purpose
BreakIterator
; it's only designed to work in a way compatible with theUnifiedHighlighter
. Some assumptions are checked with Java assertions.
-
-
Field Summary
Fields Modifier and Type Field Description private java.text.BreakIterator
baseIter
private int
currentCache
private float
fragmentAlignment
private boolean
isMinimumLength
private int
lengthGoal
-
Constructor Summary
Constructors Modifier Constructor Description private
LengthGoalBreakIterator(java.text.BreakIterator baseIter, int lengthGoal, float fragmentAlignment, boolean isMinimumLength, int currentCache)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Object
clone()
static LengthGoalBreakIterator
createClosestToLength(java.text.BreakIterator baseIter, int targetLength, float fragmentAlignment)
Breaks will be on averagetargetLength
apart; the closest break to this target (before or after) is chosen.static LengthGoalBreakIterator
createMinLength(java.text.BreakIterator baseIter, int minLength, float fragmentAlignment)
Breaks will be at leastminLength
apart (to the extent possible), while trying to position the match inside the fragment according tofragmentAlignment
.int
current()
int
first()
int
following(int matchEndIndex)
private int
following(int matchEndIndex, int targetIdx)
java.text.CharacterIterator
getText()
boolean
isBoundary(int offset)
int
last()
int
next()
int
next(int n)
int
preceding(int matchStartIndex)
int
previous()
void
setText(java.lang.String newText)
void
setText(java.text.CharacterIterator newText)
java.lang.String
toString()
-
-
-
Method Detail
-
createMinLength
public static LengthGoalBreakIterator createMinLength(java.text.BreakIterator baseIter, int minLength, float fragmentAlignment)
Breaks will be at leastminLength
apart (to the extent possible), while trying to position the match inside the fragment according tofragmentAlignment
.
-
createClosestToLength
public static LengthGoalBreakIterator createClosestToLength(java.text.BreakIterator baseIter, int targetLength, float fragmentAlignment)
Breaks will be on averagetargetLength
apart; the closest break to this target (before or after) is chosen. The match will be positioned according tofragmentAlignment
as much as possible.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
clone
public java.lang.Object clone()
- Overrides:
clone
in classjava.text.BreakIterator
-
getText
public java.text.CharacterIterator getText()
- Specified by:
getText
in classjava.text.BreakIterator
-
setText
public void setText(java.lang.String newText)
- Overrides:
setText
in classjava.text.BreakIterator
-
setText
public void setText(java.text.CharacterIterator newText)
- Specified by:
setText
in classjava.text.BreakIterator
-
current
public int current()
- Specified by:
current
in classjava.text.BreakIterator
-
first
public int first()
- Specified by:
first
in classjava.text.BreakIterator
-
last
public int last()
- Specified by:
last
in classjava.text.BreakIterator
-
next
public int next(int n)
- Specified by:
next
in classjava.text.BreakIterator
-
next
public int next()
- Specified by:
next
in classjava.text.BreakIterator
-
previous
public int previous()
- Specified by:
previous
in classjava.text.BreakIterator
-
following
public int following(int matchEndIndex)
- Specified by:
following
in classjava.text.BreakIterator
-
following
private int following(int matchEndIndex, int targetIdx)
-
preceding
public int preceding(int matchStartIndex)
- Overrides:
preceding
in classjava.text.BreakIterator
-
isBoundary
public boolean isBoundary(int offset)
- Overrides:
isBoundary
in classjava.text.BreakIterator
-
-