LUCENE-3697: SimpleBoundaryScanner does not work well when highlighting at the beginning of the text

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1232769 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Koji Sekiguchi 2012-01-18 07:34:56 +00:00
parent ff5b709b3a
commit 3150fae20d
4 changed files with 12 additions and 1 deletions

View File

@ -189,6 +189,9 @@ Bug Fixes
* LUCENE-3686: CategoryEnhancement must override Object.equals(Object).
(Sivan Yogev via Shai Erera)
* LUCENE-3697: SimpleBoundaryScanner does not work well when highlighting
at the beginning of the text. (Shay Banon via Koji Sekiguchi)
Documentation
* LUCENE-3599: Javadocs for DistanceUtils.haversine() were incorrectly

View File

@ -61,6 +61,10 @@ public class SimpleBoundaryScanner implements BoundaryScanner {
if( boundaryChars.contains( buffer.charAt( offset - 1 ) ) ) return offset;
offset--;
}
// if we scanned up to the start of the text, return it, its a "boundary"
if (offset == 0) {
return 0;
}
// not found
return start;
}

View File

@ -36,6 +36,10 @@ public class SimpleBoundaryScannerTest extends LuceneTestCase {
start = TEXT.indexOf("formance");
int expected = TEXT.indexOf("high-performance");
assertEquals(expected, scanner.findStartOffset(text, start));
start = TEXT.indexOf("che");
expected = TEXT.indexOf("Apache");
assertEquals(expected, scanner.findStartOffset(text, start));
}
public void testFindEndOffset() throws Exception {

View File

@ -173,6 +173,6 @@ public class SimpleFragmentsBuilderTest extends AbstractTestCase {
FieldFragList ffl = sflb.createFieldFragList( fpl, 100 );
SimpleFragmentsBuilder sfb = new SimpleFragmentsBuilder();
sfb.setMultiValuedSeparator( '/' );
assertEquals( " b c//<b>d</b> e", sfb.createFragment( reader, 0, F, ffl ) );
assertEquals( "//a b c//<b>d</b> e", sfb.createFragment( reader, 0, F, ffl ) );
}
}