fragCharSize prevent IAOOB here
+ spanStart = currentPhraseStartOffset - newMargin;
+ if (spanStart < startOffset) {
+ spanStart = startOffset;
+ }
+ // whatever is bigger here we grow this out
+ spanEnd = spanStart + Math.max(matchLen, fragCharSize);
+ startOffset = spanEnd;
+ fieldFragList.add(spanStart, spanEnd, wpil);
}
return fieldFragList;
}
+
+ /**
+ * A predicate to decide if the given {@link WeightedPhraseInfo} should be
+ * accepted as a highlighted phrase or if it should be discarded.
+ *
+ * The default implementation discards phrases that are composed of more than one term
+ * and where the matchLength exceeds the fragment character size.
+ *
+ * @param info the phrase info to accept
+ * @param matchLength the match length of the current phrase
+ * @param fragCharSize the configured fragment character size
+ * @return true if this phrase info should be accepted as a highligh phrase
+ */
+ protected boolean acceptPhrase(WeightedPhraseInfo info, int matchLength, int fragCharSize) {
+ return info.getTermsOffsets().size() <= 1 || matchLength <= fragCharSize;
+ }
+
+ private static final class IteratorQueue {
+ private final Iterator iter;
+ private T top;
+
+ public IteratorQueue(Iterator iter) {
+ this.iter = iter;
+ T removeTop = removeTop();
+ assert removeTop == null;
+ }
+
+ public T top() {
+ return top;
+ }
+
+ public T removeTop() {
+ T currentTop = top;
+ if (iter.hasNext()) {
+ top = iter.next();
+ } else {
+ top = null;
+ }
+ return currentTop;
+ }
+
+ }
+
}
Index: lucene/highlighter/src/java/org/apache/lucene/search/vectorhighlight/FieldPhraseList.java
===================================================================
--- lucene/highlighter/src/java/org/apache/lucene/search/vectorhighlight/FieldPhraseList.java (revision 1464648)
+++ lucene/highlighter/src/java/org/apache/lucene/search/vectorhighlight/FieldPhraseList.java (working copy)
@@ -81,7 +81,7 @@
if( ti != null )
nextMap = currMap.getTermMap( ti.getText() );
if( ti == null || nextMap == null ){
- if( ti != null )
+ if( ti != null )
fieldTermStack.push( ti );
if( currMap.isValidTermOrPhrase( phraseCandidate ) ){
addIfNoOverlap( new WeightedPhraseInfo( phraseCandidate, currMap.getBoost(), currMap.getTermOrPhraseNumber() ) );