private void alternateField(
      NamedList docSummaries, SolrParams params, Document doc, String fieldName) {
    String alternateField = params.getFieldParam(fieldName, HighlightParams.ALTERNATE_FIELD);
    if (alternateField != null && alternateField.length() > 0) {
      IndexableField[] docFields = doc.getFields(alternateField);
      List<String> listFields = new ArrayList<String>();
      for (IndexableField field : docFields) {
        if (field.binaryValue() == null) listFields.add(field.stringValue());
      }

      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);
        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
                    ? encoder.encodeText(new String(altText.substring(0, alternateFieldLen - len)))
                    : encoder.encodeText(altText));
            len += altText.length();
            if (len >= alternateFieldLen) break;
          }
        }
        docSummaries.add(fieldName, altList);
      }
    }
  }
 protected String makeFragment(
     StringBuilder buffer,
     int[] index,
     Field[] values,
     WeightedFragInfo fragInfo,
     String[] preTags,
     String[] postTags,
     Encoder encoder) {
   StringBuilder fragment = new StringBuilder();
   final int s = fragInfo.getStartOffset();
   int[] modifiedStartOffset = {s};
   String src =
       getFragmentSourceMSO(
           buffer, index, values, s, fragInfo.getEndOffset(), modifiedStartOffset);
   int srcIndex = 0;
   for (SubInfo subInfo : fragInfo.getSubInfos()) {
     for (Toffs to : subInfo.getTermsOffsets()) {
       fragment
           .append(
               encoder.encodeText(
                   src.substring(srcIndex, to.getStartOffset() - modifiedStartOffset[0])))
           .append(getPreTag(preTags, subInfo.getSeqnum()))
           .append(
               encoder.encodeText(
                   src.substring(
                       to.getStartOffset() - modifiedStartOffset[0],
                       to.getEndOffset() - modifiedStartOffset[0])))
           .append(getPostTag(postTags, subInfo.getSeqnum()));
       srcIndex = to.getEndOffset() - modifiedStartOffset[0];
     }
   }
   fragment.append(encoder.encodeText(src.substring(srcIndex)));
   return fragment.toString();
 }
 protected void append(StringBuilder dest, String content, int start, int end) {
   dest.append(encoder.encodeText(content.substring(start, end)));
 }