| 142 | } |
| 143 | |
| 144 | private getBestSnippetForMatch(result: SearchResult): string { |
| 145 | const hierarchy = result._snippetResult.hierarchy; |
| 146 | if (hierarchy === undefined) { |
| 147 | return ''; |
| 148 | } |
| 149 | |
| 150 | // return the most specific subheader match |
| 151 | if (matched(hierarchy.lvl4)) { |
| 152 | return hierarchy.lvl4!.value; |
| 153 | } |
| 154 | if (matched(hierarchy.lvl3)) { |
| 155 | return hierarchy.lvl3!.value; |
| 156 | } |
| 157 | if (matched(hierarchy.lvl2)) { |
| 158 | return hierarchy.lvl2!.value; |
| 159 | } |
| 160 | // if no subheader matched the query, fall back to just returning the most specific one |
| 161 | return hierarchy.lvl3?.value ?? hierarchy.lvl2?.value ?? ''; |
| 162 | } |
| 163 | |
| 164 | /** |
| 165 | * Returns an HTML string with marked text for the matches |