| 128 | } |
| 129 | |
| 130 | private getBestSnippetForMatch(result: SearchResult): string { |
| 131 | const hierarchy = result._snippetResult.hierarchy; |
| 132 | if (hierarchy === undefined) { |
| 133 | return ''; |
| 134 | } |
| 135 | |
| 136 | // return the most specific subheader match |
| 137 | if (matched(hierarchy.lvl4)) { |
| 138 | return hierarchy.lvl4!.value; |
| 139 | } |
| 140 | if (matched(hierarchy.lvl3)) { |
| 141 | return hierarchy.lvl3!.value; |
| 142 | } |
| 143 | if (matched(hierarchy.lvl2)) { |
| 144 | return hierarchy.lvl2!.value; |
| 145 | } |
| 146 | // if no subheader matched the query, fall back to just returning the most specific one |
| 147 | return hierarchy.lvl3?.value ?? hierarchy.lvl2?.value ?? ''; |
| 148 | } |
| 149 | |
| 150 | /** |
| 151 | * Returns an HTML string with marked text for the matches |