The Summary class configures how OpenSearch generates snippets and highlights matched keywords in search results. Use it to control the source field, snippet length, number of snippets, highlight element, and truncation string.
Quick start
The following example shows how to build a Summary object and configure it for a typical search result display:
Summary summary = new Summary("content") // extract snippets from the "content" field
.setSummary_len(200) // limit each snippet to 200 bytes
.setSummary_snippet(3) // return up to 3 snippets per query
.setSummary_element("em") // wrap matched keywords in <em> tags
.setSummary_ellipsis("..."); // append "..." when content is truncatedAll setter methods return the current Summary object, so you can chain calls as shown above.
Constructors
| Constructor | Description |
|---|---|
Summary(String summary_field) | Creates a Summary object with the specified source field. |
Summary(Summary other) | Creates a Summary object using another Summary object as a parameter. |
Summary() | Creates a Summary object with no initial configuration. |
Parameters
| Parameter | Type | Description |
|---|---|---|
summary_field | String | The field from which summaries are extracted. |
other | Summary | The Summary object. |
Methods
setSummary_field
Summary setSummary_field(String summary_field)Sets the field from which summaries are extracted.
| Parameter | Type | Description |
|---|---|---|
summary_field | String | The field from which summaries are extracted. |
Returns: the current Summary object.
getSummary_field
String getSummary_field()Returns the field configured for summary extraction.
Returns: the field name. Type: String.
setSummary_len
Summary setSummary_len(int summary_len)Sets the maximum length of each summary snippet.
| Parameter | Type | Description |
|---|---|---|
summary_len | int | The maximum length of each snippet, in bytes. Each letter or digit counts as one byte. |
Returns: the current Summary object.
getSummary_len
String getSummary_len()Returns the configured maximum snippet length.
Returns: the snippet length. Type: String.
setSummary_element
Summary setSummary_element(String summary_element)Sets the HTML element used to wrap matched keywords in summary snippets.
| Parameter | Type | Description |
|---|---|---|
summary_element | String | The HTML element used to highlight matched keywords. Valid values: em or a custom element name. |
Returns: the current Summary object.
getSummary_element
String getSummary_element()Returns the configured highlight element.
Returns: the element name. Type: String.
setSummary_ellipsis
Summary setSummary_ellipsis(String summary_ellipsis)Sets the string used to indicate truncated content in summary snippets.
| Parameter | Type | Description |
|---|---|---|
summary_ellipsis | String | The string used to represent the data that is not displayed. Example: "...". |
Returns: the current Summary object.
getSummary_ellipsis
String getSummary_ellipsis()Returns the configured ellipsis string.
Returns: the ellipsis string. Type: String.
setSummary_snippet
Summary setSummary_snippet(int summary_snippet)Sets the maximum number of summary snippets returned per query.
| Parameter | Type | Description |
|---|---|---|
summary_snippet | int | The maximum number of snippets returned per query. |
Returns: the current Summary object.
getSummary_snippet
String getSummary_snippet()Returns the configured maximum snippet count.
Returns: the snippet count. Type: String.