// nothing to highlight
return createDefaultExcerpt(text, excerptStart, excerptEnd,
fragmentStart, fragmentEnd, surround * 2);
}
PriorityQueue bestFragments = new FragmentInfoPriorityQueue(maxFragments);
for (int i = 0; i < offsets.length; i++) {
if (offsets[i].getEndOffset() <= text.length()) {
FragmentInfo fi = new FragmentInfo(offsets[i], surround * 2);
for (int j = i + 1; j < offsets.length; j++) {
if (offsets[j].getEndOffset() > text.length()) {
break;
}
if (!fi.add(offsets[j], text)) {
break;
}
}
bestFragments.insert(fi);
}
}
if (bestFragments.size() == 0) {
return createDefaultExcerpt(text, excerptStart, excerptEnd,
fragmentStart, fragmentEnd, surround * 2);
}
// retrieve fragment infos from queue and fill into list, least
// fragment comes out first
List<FragmentInfo> infos = new LinkedList<FragmentInfo>();
while (bestFragments.size() > 0) {
FragmentInfo fi = (FragmentInfo) bestFragments.pop();
infos.add(0, fi);
}
Map<TermVectorOffsetInfo, Object> offsetInfos = new IdentityHashMap<TermVectorOffsetInfo, Object>();
// remove overlapping fragment infos