the following code has a bug of StringIndexOutofBounds when multiple matched
terms need highlight

private String makeFragment( WeightedFragInfo fragInfo, String src, int s,
      String[] preTags, String[] postTags, Encoder encoder ){
    StringBuilder fragment = new StringBuilder();
    int srcIndex = 0;
    for( SubInfo subInfo : fragInfo.subInfos ){
      for( Toffs to : subInfo.termsOffsets ){
        fragment
          .append( encoder.encodeText( src.substring( srcIndex,
to.startOffset - s ) ) )
          .append( getPreTag( preTags, subInfo.seqnum ) )
          .append( encoder.encodeText( src.substring( to.startOffset - s,
to.endOffset - s ) ) )
          .append( getPostTag( postTags, subInfo.seqnum ) );
        srcIndex = to.endOffset - s;
      }
    }
    fragment.append( encoder.encodeText( src.substring( srcIndex ) ) );
    return fragment.toString();
  }--
王巍巍
Cell: 18911288489
MSN: ww.wang...@gmail.com
Blog: http://whisper.eyesay.org
围脖:http://t.sina.com/lolorosa

Reply via email to