--- Highlighter.java 2006-08-31 10:44:21.000000000 +0800 +++ Highlighter.java 2006-09-12 14:52:14.000000000 +0800 @@ -224,14 +224,14 @@ while ((token = tokenStream.next()) != null) { - if((tokenGroup.numTokens>0)&&(tokenGroup.isDistinct(token))) + if((tokenGroup.numTokens>0 && tokenGroup.isDistinct(token)) || (tokenGroup.getTotalScore() > 0)) { //the current token is distinct from previous tokens - // markup the cached token group info startOffset = tokenGroup.matchStartOffset; endOffset = tokenGroup.matchEndOffset; - tokenText = text.substring(startOffset, endOffset); - String markedUpText=formatter.highlightTerm(encoder.encodeText(tokenText), tokenGroup); + tokenText = text.substring(Math.max(startOffset, lastEndOffset), endOffset); + String markedUpText=tokenText.equals("") ? "" : formatter.highlightTerm(encoder.encodeText(tokenText), tokenGroup); //store any whitespace etc from between this and last group if (startOffset > lastEndOffset) newText.append(encoder.encodeText(text.substring(lastEndOffset, startOffset))); @@ -265,8 +265,8 @@ //flush the accumulated text (same code as in above loop) startOffset = tokenGroup.matchStartOffset; endOffset = tokenGroup.matchEndOffset; - tokenText = text.substring(startOffset, endOffset); - String markedUpText=formatter.highlightTerm(encoder.encodeText(tokenText), tokenGroup); + tokenText = text.substring(Math.max(startOffset, lastEndOffset), endOffset); + String markedUpText=tokenText.equals("") ? "" : formatter.highlightTerm(encoder.encodeText(tokenText), tokenGroup); //store any whitespace etc from between this and last group if (startOffset > lastEndOffset) newText.append(encoder.encodeText(text.substring(lastEndOffset, startOffset))); @@ -275,8 +275,8 @@ } // append text after end of last token -// if (lastEndOffset < text.length()) -// newText.append(encoder.encodeText(text.substring(lastEndOffset))); + if (lastEndOffset < text.length()) + newText.append(encoder.encodeText(text.substring(lastEndOffset))); currentFrag.textEndPos = newText.length();