Skip to content

Commit

Permalink
fix(hits): default to hierarchy lvl0 if highlights present (#2309)
Browse files Browse the repository at this point in the history
  • Loading branch information
shortcuts authored Sep 27, 2024
1 parent 9733ba9 commit 5260d1e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
6 changes: 3 additions & 3 deletions examples/demo/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ function App() {
<div>
<h1>DocSearch v3 - React</h1>
<DocSearch
indexName="docsearch"
appId="R2IYF7ETH7"
apiKey="599cec31baffa4868cae4e79f180729b"
indexName="vuejs"
appId="ML0LEBN7FQ"
apiKey="21cf9df0734770a2448a9da64a700c22"
insights
/>
</div>
Expand Down
18 changes: 10 additions & 8 deletions packages/docsearch-react/src/utils/removeHighlightTags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ export function removeHighlightTags(
return hit.hierarchy.lvl0;
}

const { value } =
(internalDocSearchHit.__docsearch_parent
? internalDocSearchHit.__docsearch_parent?._highlightResult?.hierarchy
?.lvl0
: hit._highlightResult?.hierarchy?.lvl0) || {};
const lvl0 = internalDocSearchHit.__docsearch_parent
? internalDocSearchHit.__docsearch_parent?._highlightResult?.hierarchy?.lvl0
: hit._highlightResult?.hierarchy?.lvl0;

return value && regexHasHighlightTags.test(value)
? value.replace(regexHighlightTags, '')
: value;
if (!lvl0) {
return hit.hierarchy.lvl0;
}

return lvl0.value && regexHasHighlightTags.test(lvl0.value)
? lvl0.value.replace(regexHighlightTags, '')
: lvl0.value;
}

0 comments on commit 5260d1e

Please sign in to comment.