while (it.hasNext()) {
FragmentInfo fi = it.next();
boolean overlap = false;
Iterator<TermVectorOffsetInfo> fit = fi.iterator();
while (fit.hasNext() && !overlap) {
TermVectorOffsetInfo oi = fit.next();
if (offsetInfos.containsKey(oi)) {
overlap = true;
}
}
if (overlap) {
it.remove();
} else {
Iterator<TermVectorOffsetInfo> oit = fi.iterator();
while (oit.hasNext()) {
offsetInfos.put(oit.next(), null);
}
}
}
// create excerpts
StringBuffer sb = new StringBuffer(excerptStart);
it = infos.iterator();
while (it.hasNext()) {
FragmentInfo fi = it.next();
sb.append(fragmentStart);
int limit = Math.max(0, fi.getStartOffset() / 2 + fi.getEndOffset() / 2 - surround);
int len = startFragment(sb, text, fi.getStartOffset(), limit);
TermVectorOffsetInfo lastOffsetInfo = null;
Iterator<TermVectorOffsetInfo> fIt = fi.iterator();
while (fIt.hasNext()) {
TermVectorOffsetInfo oi = fIt.next();
if (lastOffsetInfo != null) {
// fill in text between terms
sb.append(text.substring(lastOffsetInfo.getEndOffset(), oi.getStartOffset()));
}
sb.append(hlStart);
sb.append(text.substring(oi.getStartOffset(), oi.getEndOffset()));
sb.append(hlEnd);
lastOffsetInfo = oi;
}
limit = Math.min(text.length(), fi.getStartOffset() - len + (surround * 2));
endFragment(sb, text, fi.getEndOffset(), limit);