mirror of https://github.com/apache/lucene.git
SOLR-2603: Encoding of alternate fields in highlighting
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1231665 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
2911bce99b
commit
2125313a90
|
@ -434,6 +434,8 @@ New Features
|
|||
* SOLR-3036: Ability to specify overwrite=false on the URL for XML updates.
|
||||
(Sami Siren via yonik)
|
||||
|
||||
* SOLR-2603: Add the encoding function for alternate fields in highlighting.
|
||||
(Massimo Schiavon, koji)
|
||||
|
||||
Optimizations
|
||||
----------------------
|
||||
|
|
|
@ -577,21 +577,23 @@ public class DefaultSolrHighlighter extends SolrHighlighter implements PluginInf
|
|||
String[] altTexts = listFields.toArray(new String[listFields.size()]);
|
||||
|
||||
if (altTexts != null && altTexts.length > 0){
|
||||
Encoder encoder = getEncoder(fieldName, params);
|
||||
int alternateFieldLen = params.getFieldInt(fieldName, HighlightParams.ALTERNATE_FIELD_LENGTH,0);
|
||||
if( alternateFieldLen <= 0 ){
|
||||
docSummaries.add(fieldName, altTexts);
|
||||
}
|
||||
else{
|
||||
List<String> altList = new ArrayList<String>();
|
||||
int len = 0;
|
||||
for( String altText: altTexts ){
|
||||
if( alternateFieldLen <= 0 ){
|
||||
altList.add(encoder.encodeText(altText));
|
||||
}
|
||||
else{
|
||||
altList.add( len + altText.length() > alternateFieldLen ?
|
||||
new String(altText.substring( 0, alternateFieldLen - len )) : altText );
|
||||
encoder.encodeText(new String(altText.substring( 0, alternateFieldLen - len ))) :
|
||||
encoder.encodeText(altText) );
|
||||
len += altText.length();
|
||||
if( len >= alternateFieldLen ) break;
|
||||
}
|
||||
docSummaries.add(fieldName, altList);
|
||||
}
|
||||
docSummaries.add(fieldName, altList);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue