({
hit,
query,
totalHits,
index,
debug,
}: {
hit: SearchResultHitT
query: string
totalHits: number
index: number
debug: boolean
})
| 69 | } |
| 70 | |
| 71 | function SearchResultHit({ |
| 72 | hit, |
| 73 | query, |
| 74 | totalHits, |
| 75 | index, |
| 76 | debug, |
| 77 | }: { |
| 78 | hit: SearchResultHitT |
| 79 | query: string |
| 80 | totalHits: number |
| 81 | index: number |
| 82 | debug: boolean |
| 83 | }) { |
| 84 | const title = |
| 85 | hit.highlights.title && hit.highlights.title.length > 0 ? hit.highlights.title[0] : hit.title |
| 86 | |
| 87 | return ( |
| 88 | <div className={cx('my-6', styles.search_result)} data-testid="search-result"> |
| 89 | <p className="text-normal f5 color-fg-muted" style={{ wordSpacing: 2 }}> |
| 90 | {hit.breadcrumbs.length > 1 && ( |
| 91 | <> |
| 92 | <strong>{hit.breadcrumbs.split('/')[0]}</strong> |
| 93 | {hit.breadcrumbs.replace(hit.breadcrumbs.split('/')[0], '')} / |
| 94 | </> |
| 95 | )} |
| 96 | </p> |
| 97 | <h2 className="f3"> |
| 98 | <Link |
| 99 | href={hit.url} |
| 100 | className="color-fg-accent" |
| 101 | dangerouslySetInnerHTML={{ __html: title }} |
| 102 | onClick={() => { |
| 103 | sendEvent({ |
| 104 | type: EventType.searchResult, |
| 105 | search_result_query: Array.isArray(query) ? query[0] : query, |
| 106 | search_result_index: index, |
| 107 | search_result_total: totalHits, |
| 108 | search_result_rank: (totalHits - index) / totalHits, |
| 109 | search_result_url: hit.url, |
| 110 | }) |
| 111 | }} |
| 112 | ></Link> |
| 113 | </h2> |
| 114 | {hit.highlights.content && hit.highlights.content.length > 0 && ( |
| 115 | <div dangerouslySetInnerHTML={{ __html: hit.highlights.content[0] }}></div> |
| 116 | )} |
| 117 | {debug && ( |
| 118 | <Text as="p" fontWeight="bold"> |
| 119 | score: <code style={{ marginRight: 10 }}>{hit.score}</code> popularity:{' '} |
| 120 | <code>{hit.popularity}</code> |
| 121 | </Text> |
| 122 | )} |
| 123 | </div> |
| 124 | ) |
| 125 | } |
| 126 | |
| 127 | function ResultsPagination({ page, totalPages }: { page: number; totalPages: number }) { |
| 128 | const router = useRouter() |
nothing calls this directly
no test coverage detected