Search Result Summary

更新时间:
复制 MD 格式

Documents are often long, making it impractical to display their full content in search results. To address this, you can configure summaries and highlighting. The system extracts text segments that contain the query terms, helping users quickly determine if a result is relevant. You can customize these display settings in the console. Once configured, these settings are automatically applied to your API search requests. You can also override the console settings for specific queries by using the summary parameter in an API call.

Parameters

  • Field: The field for which to generate a summary.

  • Segment length: The maximum length of each summary segment.

  • Highlight tag: The HTML tag used to highlight keywords.

  • Segment connector: The string used to connect summary segments.

  • Number of segments: The maximum number of segments to return.

Configure in the console

1. In the console, go to Feature Extensions > Search Result Display to configure the summary.

00000000000000000000

2. The following example shows how to configure the highlight tag.

In the example, a summary is configured for the title field. The segment length is 50, the highlight tag is em, the segment connector is ..., and the number of segments is 5.

API and SDK configuration

  • API parameter: Specify the settings by using the summary parameter.

  • SDK configuration: The following example shows how to configure the summary by using the Java SDK:

    // Configure the search result summary. Using the Summary object is a convenient way to add summary settings.
        Summary summ = new Summary("name");
        summ.setSummary_field("name");// The field to which the summary applies. This must be a TEXT field with an analyzer.
        summ.setSummary_len("50");// The segment length.
        summ.setSummary_element("em"); // The highlight tag.
        summ.setSummary_ellipsis("...");// The segment connector.
        summ.setSummary_snippet("1");// The number of segments.
        // Add the Summary object.

    Note:

  • You cannot specify separate prefixes and suffixes for a highlight tag in the summary object of the SearchParams class. You must provide a complete HTML tag. For example, if you set the highlight tag to em, the highlighted result in the JSON response for "Alibaba Cloud OpenSearch product document" is Alibaba Cloud<em>OpenSearch</em>product document.

  • To set custom prefixes and suffixes for a highlight tag in the SDK, use the SearchParamsBuilder object.

    // A utility class for SearchParams that provides more flexible operations.
          SearchParamsBuilder paramsBuilder = SearchParamsBuilder.create(searchParams);
          // Use the SearchParamsBuilder object to add summary settings.
    paramsBuilder.addCustomParam("summary", "summary_field:name,summary_ellipsis:...,summary_snippet:1,summary_len:50,summary_element_prefix:<abc>,summary_element_postfix:</abc>");
         // To specify multiple summary fields, separate them with semicolons (;).

    Important notes

  • Highlighting applies only to the terms in your query. The field configured for highlighting must be indexed. Otherwise, highlighting may not work as expected.

  • You must configure summary and highlighting settings together.

  • When you configure a summary for multiple fields, matching query terms are highlighted in all specified fields.

  • If a matching term appears far into a document, beyond a 10,000-byte limit, it is not highlighted.

  • During highlighting, any literal angle brackets (< and >) in the source text are escaped to &lt; and &gt; in the output.

  • If you apply different analyzers to the same field, such as a standard Chinese analyzer and a single-character analyzer, highlighting may be incorrect or incomplete. The summary might only match terms based on one analyzer or highlight the wrong content.

  • If a single query uses two or more indexes with different analyzers for search, highlighting may fail or behave unpredictably.

  • By default, special characters are filtered from highlighted segments. To display these characters, set the kvpairs clause to filter_punc:0 to disable this filtering.

Summary and highlighting example

After searching for the keyword friendship, the search results list displays a summary segment for each entry, with the matched keyword highlighted. Each result includes fields such as title, source, author, category, status, word count, and rating, along with a Start Reading button. At the top of the page, you can also filter results by category, word count, and status, or sort by criteria like update time, rating count, and subscription count.