Jumping to the Matching Text from Search Results
Search results in your Knowledge Base now open articles at the sentence that matched, highlighted, so readers land on the answer instead of the top of the page.
Long articles are great for covering a topic properly, but not so great when a reader only needs one sentence of it. Now when someone clicks a search result, the article opens scrolled to the passage that matched their search, with it highlighted, so they land right on the answer. β¨
There's nothing to switch on. It works automatically in every built-in template.
Where It Works
Results link to the matching text in:
- The full search results page
- The search dropdown that appears as you type
- Instant search
- Suggested articles in the contact form
Ask AI sources and the Lighthouse widget still open articles at the top.
How It Works
When a search matches an article, we pick the sentence that best matches what the reader typed and add a text fragment to the end of the result's link. It looks something like this:
/article/abc123-custom-domains#:~:text=Add%20a%20CNAME%20recordThe reader's browser uses that to scroll to the sentence and highlight it. Your article URLs themselves don't change, so anything that links to your articles keeps working exactly as before.
A few things are worth knowing:
- Title matches open at the top. If an article's title already contains everything the reader searched for, the whole article is the answer, so it opens at the top as normal.
- Sentences with variables are skipped. If a sentence contains a variable, we pick a different one, since the text on the page won't match what's in the search index.
- If the text can't be found, nothing breaks. The article simply opens at the top, just as it did before.
Browser Support
Text fragments work in Chrome, Edge, Safari 16.1 and later, and Firefox 131 and later. Readers on other browsers get a regular link to the article.
Adding it to a custom template
If you use a custom HTML template, your search results won't change until you opt in. Each search result has a text_fragment property. Add it straight after relative_url in your result links.
In search.hbs:
<a href="{{this.relative_url}}{{this.text_fragment}}">{{this.title}}</a>If you override the instant search result template in default.hbs, escape the braces like the rest of that template:
<a href="\{\{relative_url\}\}\{\{text_fragment\}\}">\{\{title\}\}</a>text_fragment at the very end of the link. It starts with #, so anything added after it, like a query string, will stop it working.text_fragment is empty when there's no good sentence to link to, so you don't need to check for it first.
What did you think of this doc?
Archiving Articles
Understanding Search Results