Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Search API Excerpts use wrong Cache tags and thus only deliver when called via AJAX/POST + better parsing #257

Open
DiegoPino opened this issue Feb 18, 2023 · 2 comments
Assignees
Labels
Drupal Views JSON Integration with VIEWS enhancement New feature or request External Bug We can help! help wanted Extra attention is needed Search API F around and find out UI/UX Experience
Milestone

Comments

@DiegoPino
Copy link
Member

What?

Excerpts that are shown on Views results and Rendered ADOs (or nodes) use only the URL context for caching, and because of that when not called via POST/AJAX (which bypasses caching) get stuck on basically not displaying anything at all when e.g a URL with the search term is called directly (the view Cache wins there).

How to get around this?

I see two options here:

  • Use a promise of a render (basically a dynamic rendered or also named in Drupal #lazy_builder)
  • Change in case Excerpts are present the global cache of a view (always adding the URL initially as a content + Max Cache time: 0 when the excerpt is produced.

@alliomeria this relates to one of our partners questions.

@DiegoPino DiegoPino self-assigned this Feb 18, 2023
@DiegoPino DiegoPino added enhancement New feature or request help wanted Extra attention is needed Drupal Views JSON Integration with VIEWS External Bug We can help! UI/UX Experience Search API F around and find out labels Feb 18, 2023
@DiegoPino DiegoPino added this to the 1.1.0 milestone Feb 18, 2023
@DiegoPino
Copy link
Member Author

DiegoPino commented Feb 18, 2023

See:

/**
 * Implements hook_entity_view().
 */
function search_api_entity_view(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display, $view_mode) {
  $excerpt_component = $display->getComponent('search_api_excerpt');
  if ($excerpt_component !== NULL && isset($build['#search_api_excerpt'])) {
    $build['search_api_excerpt'] = [
      '#type' => 'markup',
      '#markup' => $build['#search_api_excerpt'],
      '#cache' => [
        'contexts' => ['url.query_args'],
      ],
    ];
  }

Another option would be (without code) to test if instead of rendering an Entity on the results we can use the "rendered entity" field and output the excerpt as an additional field. That way the excerpt is generated by the Row plugin in Views instead of the actual hook_entity_view() for nodes/view mode. Of course this does not give is much freedom for placing the excerpt inside an existing layout ... mmm

@DiegoPino
Copy link
Member Author

@DiegoPino DiegoPino changed the title Search API Excerpts use wrong Cache tags and thus only deliver when called via AJAX/POST Search API Excerpts use wrong Cache tags and thus only deliver when called via AJAX/POST + better parsing Feb 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Drupal Views JSON Integration with VIEWS enhancement New feature or request External Bug We can help! help wanted Extra attention is needed Search API F around and find out UI/UX Experience
Projects
None yet
Development

No branches or pull requests

1 participant