Highlight excerpts in frontend only works with twig files with an initial activation of option excerpt_always

Created on 13 October 2023, about 1 year ago
Updated 16 October 2023, about 1 year ago

Problem/Motivation

Using Highlight excerpts in the backend view works without active "Create excerpt even if no search keys are available". But on the frontend using a template node.html.twig overwrite, this is still empty. Also, if a search key "test" is given.
Only with activated excerpt_always I got the excerpts in my frontend.

Steps to reproduce

  • bundle "news" with display mode "search result highlighting input" with only the field "Search result excerpt"
  • View of "Index Default content index" with rendered entity (view mode for bundle "news" --> search result highlighting input)
  • Filter with fulltext search for setting the search string
  • A theme with a template file node.html.twig (like classy or stable9) with the div
  • In the view preview, I enter "test" and I got the highlight preview.

Proposed resolution

The empty div in the frontend should be filled with the excerpt value like in the view preview.

My task for solution

To solve the problem, I activate and deactivate the processors highlight checkbox "Create excerpt even if no search keys are available" (/admin/config/search/search-api/index/default_index/processors). Also clear cache (drush cr).

After that, the excerpt is (also with empty key) in the frontend filled like the view preview (backend view).

As info, the yml file of view display the bundle "news" for the mode "search_result":

langcode: en
status: true
dependencies:
  config:
    - core.entity_view_mode.node.search_result
    - field.field.node.news.field_parapage_content
    - node.type.news
  module:
    - media
    - paragraphs
    - user
id: node.news.search_result
targetEntityType: node
bundle: news
mode: search_result
content:
  search_api_excerpt:
    settings: {  }
    third_party_settings: {  }
    weight: 0
    region: content
hidden:
  field_parapage_content: true
  links: true
🐛 Bug report
Status

Closed: works as designed

Version

1.29

Component

General code

Created by

🇩🇪Germany thomaswalther Rhein-Main Area

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @thomaswalther
  • Assigned to Shreya_98
  • 🇩🇪Germany thomaswalther Rhein-Main Area

    Update:
    when I install my custom theme and after that I set config via drush for excerpt_always to true then it worked in the frontend. If I deactivate it, the field is empty (only in the frontend). Preview of view is correct.

    drush config:set --input-format=yaml search_api.index.default_index processor_settings.highlight "{\
       weights: {postprocess_query: 0} \
       , prefix: '<strong>' ,\
       suffix: '</strong>'\
       , excerpt: true\
       , excerpt_always: true\
       , excerpt_length: 256\
       , exclude_fields: {}\
       , highlight: always\
       , highlight_partial: true\
       }"
  • Status changed to Postponed: needs info about 1 year ago
  • 🇦🇹Austria drunken monkey Vienna, Austria

    Sorry, could not reproduce. Could you provide a failing test case?

  • Status changed to Closed: works as designed about 1 year ago
  • 🇩🇪Germany thomaswalther Rhein-Main Area

    I tested today again. I also can not reproduce it. Maybe it seems to be an indexed, Drupal or twig cached problem.
    It worked fine after reindex or flush cache.

Production build 0.71.5 2024