lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Weiwei Wang <ww.wang...@gmail.com>
Subject FastVectorHighlighter StringIndexOutofBounds bug
Date Mon, 23 May 2011 05:24:44 GMT
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.cs@gmail.com
Blog: http://whisper.eyesay.org
围脖:http://t.sina.com/lolorosa

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message