org.apache.lucene.search.postingshighlight

## Class DefaultPassageFormatter

- java.lang.Object
- - org.apache.lucene.search.postingshighlight.PassageFormatter
  - - org.apache.lucene.search.postingshighlight.DefaultPassageFormatter

-     public class DefaultPassageFormatter
      extends PassageFormatter

  Creates a formatted snippet from the top passages.

  The default implementation marks the query terms as bold, and places ellipses between unconnected passages.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected String` | `ellipsis` text that will appear between two unconnected passages
    `protected boolean` | `escape` true if we should escape for html
    `protected String` | `postTag` text that will appear after highlighted terms
    `protected String` | `preTag` text that will appear before highlighted terms

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `DefaultPassageFormatter()` Creates a new DefaultPassageFormatter with the default tags.
    `DefaultPassageFormatter(String preTag, String postTag, String ellipsis, boolean escape)` Creates a new DefaultPassageFormatter with custom tags.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected void` | `append(StringBuilder dest, String content, int start, int end)` Appends original text to the response.
    `String` | `format(Passage[] passages, String content)` Formats the top `passages` from `content` into a human-readable text snippet.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### preTag

          protected final String preTag

      text that will appear before highlighted terms

    - #### postTag

          protected final String postTag

      text that will appear after highlighted terms

    - #### ellipsis

          protected final String ellipsis

      text that will appear between two unconnected passages

    - #### escape

          protected final boolean escape

      true if we should escape for html

  - ### Constructor Detail

    - #### DefaultPassageFormatter

          public DefaultPassageFormatter()

      Creates a new DefaultPassageFormatter with the default tags.

    - #### DefaultPassageFormatter

          public DefaultPassageFormatter(String preTag,
                                 String postTag,
                                 String ellipsis,
                                 boolean escape)

      Creates a new DefaultPassageFormatter with custom tags.
      Parameters:
        `preTag` - text which should appear before a highlighted term.
        `postTag` - text which should appear after a highlighted term.
        `ellipsis` - text which should be used to connect two unconnected passages.
        `escape` - true if text should be html-escaped

  - ### Method Detail

    - #### format

          public String format(Passage[] passages,
                      String content)

      Description copied from class: `PassageFormatter`
      Formats the top `passages` from `content` into a human-readable text snippet.
      Specified by:
        `format` in class `PassageFormatter`
      Parameters:
        `passages` - top-N passages for the field. Note these are sorted in the order that they appear in the document for convenience.
        `content` - content for the field.
      Returns:
        formatted highlight. Note that for the non-expert APIs in `PostingsHighlighter` that return String, the toString method on the Object returned by this method is used to compute the string.

    - #### append

          protected void append(StringBuilder dest,
                    String content,
                    int start,
                    int end)

      Appends original text to the response.
      Parameters:
        `dest` - resulting text, possibly transformed or encoded
        `content` - original text content
        `start` - index of the first character in content
        `end` - index of the character following the last character in content

Copyright © 2000-2017 Apache Software Foundation. All Rights Reserved.