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

[5.x] Include Algolia highlights and snippets #11008

Merged
merged 1 commit into from
Oct 25, 2024

Conversation

jacksleight
Copy link
Contributor

@jacksleight jacksleight commented Oct 25, 2024

This PR adds Algolia's highlights and snippets to the result data. Highlights are usually included by default, snippets can be included with these settings:

'default' => [
    'driver' => 'algolia',
    'settings' => [
        'attributesToSnippet' => ['content:40'],
        'highlightPreTag' => '<mark>',
        'highlightPostTag' => '</mark>',
    ],
],

You can then use them in results:

<a href="{{ $url }}">
    <h2>{{ search_highlights:title:value }}</h2>
    <p>{{ search_snippets:content:value }}</p>
</a>

Screenshot 2024-10-25 at 09 42 49

The key names are based on the convention established in the comb driver for snippets.

@jacksleight jacksleight changed the title Augment Algolia highlights and snippets [5.x] Augment Algolia highlights and snippets Oct 25, 2024
@jacksleight jacksleight changed the title [5.x] Augment Algolia highlights and snippets [5.x] Include Algolia highlights and snippets Oct 25, 2024
@jasonvarga jasonvarga merged commit 1a3e110 into statamic:5.x Oct 25, 2024
21 checks passed
@jacksleight jacksleight deleted the featuure/algolia-snippets branch October 25, 2024 19:14
@daun
Copy link
Contributor

daun commented Nov 26, 2024

@jacksleight I just discovered this – great stuff! Got me inspired to implement proper snippet generation for the Loupe search driver. While Loupe already includes highlighting, it doesn't currently offer snippets, so this seemed like a nice feature to add. Thanks for the inspiration!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants