FragmentInfo fi = (FragmentInfo)it.next();
boolean overlap = false;
Iterator fit = fi.iterator();
while (fit.hasNext() && !overlap)
{
TermVectorOffsetInfo oi = (TermVectorOffsetInfo)fit.next();
if (offsetInfos.containsKey(oi))
{
overlap = true;
}
}
if (overlap)
{
it.remove();
}
else
{
Iterator 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 = (FragmentInfo)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 fIt = fi.iterator();
while (fIt.hasNext())
{
TermVectorOffsetInfo oi = (TermVectorOffsetInfo)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);