mirror of https://github.com/apache/lucene.git
LUCENE-2603: FastVectorHighlighter: add a method to set an arbitrary char that is used when concatenating multiValued data
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@986173 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
c2df8e8a0c
commit
db4b2af8af
|
@ -112,6 +112,10 @@ API Changes
|
|||
such as stopword lists and any language-specific processing in addition to
|
||||
stemming. Add Turkish and Romanian stopwords lists to support this.
|
||||
(Robert Muir, Uwe Schindler, Simon Willnauer)
|
||||
|
||||
* LUCENE-2603: Add setMultiValuedSeparator(char) method to set an arbitrary
|
||||
char that is used when concatenating multiValued data. Default is a space
|
||||
(' '). It is applied on ANALYZED field only. (Koji Sekiguchi)
|
||||
|
||||
New features
|
||||
|
||||
|
|
|
@ -44,6 +44,7 @@ public abstract class BaseFragmentsBuilder implements FragmentsBuilder {
|
|||
"<b style=\"background:turquoise\">", "<b style=\"background:powderblue\">"
|
||||
};
|
||||
public static final String[] COLORED_POST_TAGS = { "</b>" };
|
||||
private char multiValuedSeparator = ' ';
|
||||
|
||||
protected BaseFragmentsBuilder(){
|
||||
this( new String[]{ "<b>" }, new String[]{ "</b>" } );
|
||||
|
@ -155,7 +156,7 @@ public abstract class BaseFragmentsBuilder implements FragmentsBuilder {
|
|||
int startOffset, int endOffset ){
|
||||
while( buffer.length() < endOffset && index[0] < values.length ){
|
||||
if( index[0] > 0 && values[index[0]].length() > 0 )
|
||||
buffer.append( ' ' );
|
||||
buffer.append( multiValuedSeparator );
|
||||
buffer.append( values[index[0]++] );
|
||||
}
|
||||
int eo = buffer.length() < endOffset ? buffer.length() : endOffset;
|
||||
|
@ -166,12 +167,20 @@ public abstract class BaseFragmentsBuilder implements FragmentsBuilder {
|
|||
int startOffset, int endOffset ){
|
||||
while( buffer.length() < endOffset && index[0] < values.length ){
|
||||
if( index[0] > 0 && values[index[0]].isTokenized() && values[index[0]].stringValue().length() > 0 )
|
||||
buffer.append( ' ' );
|
||||
buffer.append( multiValuedSeparator );
|
||||
buffer.append( values[index[0]++].stringValue() );
|
||||
}
|
||||
int eo = buffer.length() < endOffset ? buffer.length() : endOffset;
|
||||
return buffer.substring( startOffset, eo );
|
||||
}
|
||||
|
||||
public void setMultiValuedSeparator( char separator ){
|
||||
multiValuedSeparator = separator;
|
||||
}
|
||||
|
||||
public char getMultiValuedSeparator(){
|
||||
return multiValuedSeparator;
|
||||
}
|
||||
|
||||
protected String getPreTag( int num ){
|
||||
return getPreTag( preTags, num );
|
||||
|
|
|
@ -148,6 +148,21 @@ public class SimpleFragmentsBuilderTest extends AbstractTestCase {
|
|||
SimpleFragListBuilder sflb = new SimpleFragListBuilder();
|
||||
FieldFragList ffl = sflb.createFieldFragList( fpl, 100 );
|
||||
SimpleFragmentsBuilder sfb = new SimpleFragmentsBuilder();
|
||||
// '/' separator doesn't effect the snippet because of NOT_ANALYZED field
|
||||
sfb.setMultiValuedSeparator( '/' );
|
||||
assertEquals( "abc<b>defg</b>hijkl", sfb.createFragment( reader, 0, F, ffl ) );
|
||||
}
|
||||
|
||||
public void testMVSeparator() throws Exception {
|
||||
makeIndexShortMV();
|
||||
|
||||
FieldQuery fq = new FieldQuery( tq( "d" ), true, true );
|
||||
FieldTermStack stack = new FieldTermStack( reader, 0, F, fq );
|
||||
FieldPhraseList fpl = new FieldPhraseList( stack, fq );
|
||||
SimpleFragListBuilder sflb = new SimpleFragListBuilder();
|
||||
FieldFragList ffl = sflb.createFieldFragList( fpl, 100 );
|
||||
SimpleFragmentsBuilder sfb = new SimpleFragmentsBuilder();
|
||||
sfb.setMultiValuedSeparator( '/' );
|
||||
assertEquals( "a b c/<b>d</b> e", sfb.createFragment( reader, 0, F, ffl ) );
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue