I’m creating a documentation website and am trying to make all content fuzzy searchable, returning individual matches from paragraphs.
I’ve gotten everything working for the most part, except for the display of the results.
This is what my index looks like (example):
[
{
"title": "A page title",
"url": "/the-url",
"content": [
"This is a paragraph",
"This is another paragraph",
"This is more as an example"
]
},
...// more items
]
The issue I’m running into is that while Algolia can match and highlight on individual strings within the content
array, it always appends them together with a comma when outputting.
For example, if I search “This is”, then ${components.Highlight({ attribute: 'content', hit })
returns the following HTML:
<span class="ais-Highlight">
<mark class="ais-Highlight-highlighted">This is</mark>
<span class="ais-Highlight-nonHighlighted">a paragraph</span>
<span class="ais-Highlight-separator">, </span>
<mark class="ais-Highlight-highlighted">This is</mark>
<span class="ais-Highlight-nonHighlighted">another paragraph</span>
<span class="ais-Highlight-separator">, </span>
<mark class="ais-Highlight-highlighted">This is</mark>
<span class="ais-Highlight-nonHighlighted">more as an example</span>
<span class="ais-Highlight-separator">, </span>
</span>
When rendered, all of the paragraphs are appended together into a giant wall of text. Ideally, I’d love to just change the separator to be something else like <br>
or something, but I’ve been searching and poking at this for hours and cannot find a way to override the separator.
I tried directly accessing hit._highlightResult.content[].value
. In the above example, that would return <mark>This is</mark> a paragraph
but Algolia can’t render HTML that’s in a variable, only if it’s entered as a string literal.
Is there a way to achieve what I’m trying to do?