LUCENE-1953: FastVectorHighlighter: small fragCharSize can cause StringIndexOutOfBoundsException

git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@823170 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Koji Sekiguchi 2009-10-08 13:34:43 +00:00
parent 886ae61113
commit 90fc7e18c7
3 changed files with 20 additions and 0 deletions

View File

@ -26,6 +26,9 @@ Bug fixes
Iterator#hasNext method on exhausted streams.
(Patrick Jungermann via Karl Wettin)
* LUCENE-1953: FastVectorHighlighter: small fragCharSize can cause
StringIndexOutOfBoundsException. (Koji Sekiguchi)
New features
* LUCENE-1924: Added BalancedSegmentMergePolicy to contrib/misc,

View File

@ -59,6 +59,8 @@ public class SimpleFragListBuilder implements FragListBuilder {
int st = phraseInfo.getStartOffset() - MARGIN < startOffset ?
startOffset : phraseInfo.getStartOffset() - MARGIN;
int en = st + fragCharSize;
if( phraseInfo.getEndOffset() > en )
en = phraseInfo.getEndOffset();
startOffset = en;
while( true ){

View File

@ -37,6 +37,21 @@ public class SimpleFragListBuilderTest extends AbstractTestCase {
}
}
public void testSmallerFragSizeThanTermQuery() throws Exception {
SimpleFragListBuilder sflb = new SimpleFragListBuilder();
FieldFragList ffl = sflb.createFieldFragList( fpl( "abcdefghijklmnopqrs", "abcdefghijklmnopqrs" ), SimpleFragListBuilder.MIN_FRAG_CHAR_SIZE );
assertEquals( 1, ffl.fragInfos.size() );
assertEquals( "subInfos=(abcdefghijklmnopqrs((0,19)))/1.0(0,19)", ffl.fragInfos.get( 0 ).toString() );
}
public void testSmallerFragSizeThanPhraseQuery() throws Exception {
SimpleFragListBuilder sflb = new SimpleFragListBuilder();
FieldFragList ffl = sflb.createFieldFragList( fpl( "\"abcdefgh jklmnopqrs\"", "abcdefgh jklmnopqrs" ), SimpleFragListBuilder.MIN_FRAG_CHAR_SIZE );
assertEquals( 1, ffl.fragInfos.size() );
System.out.println( ffl.fragInfos.get( 0 ).toString() );
assertEquals( "subInfos=(abcdefghjklmnopqrs((0,21)))/1.0(0,21)", ffl.fragInfos.get( 0 ).toString() );
}
public void test1TermIndex() throws Exception {
SimpleFragListBuilder sflb = new SimpleFragListBuilder();
FieldFragList ffl = sflb.createFieldFragList( fpl( "a", "a" ), 100 );