Skip to content

Commit 8b60652

Browse files
committed
add search results title highlighting
1 parent 390cbf6 commit 8b60652

File tree

1 file changed

+30
-15
lines changed

1 file changed

+30
-15
lines changed

search.js

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ function initializeMeilisearchIntegration() {
422422
// Perform search
423423
index.search(query, {
424424
limit: 25,
425-
attributesToHighlight: ['title', 'content'],
425+
attributesToHighlight: ['hierarchy_lvl1', 'hierarchy_lvl2', 'hierarchy_lvl3', 'hierarchy_lvl4', 'hierarchy_lvl5', 'content'],
426426
attributesToCrop: ['content'],
427427
cropLength: 100,
428428
hybrid: {
@@ -480,26 +480,41 @@ function initializeMeilisearchIntegration() {
480480

481481
// Format content nicely
482482
// Build title from hierarchy levels
483+
const hierarchy_lvl1 = hit._formatted?.hierarchy_lvl1
484+
? hit._formatted.hierarchy_lvl1.replace(/<em>/g, '<em style="font-style: normal; color: #f472b6; font-weight: bold;">')
485+
: '';
486+
const hierarchy_lvl2 = hit._formatted?.hierarchy_lvl2
487+
? hit._formatted.hierarchy_lvl2.replace(/<em>/g, '<em style="font-style: normal; color: #f472b6; font-weight: bold;">')
488+
: '';
489+
const hierarchy_lvl3 = hit._formatted?.hierarchy_lvl3
490+
? hit._formatted.hierarchy_lvl3.replace(/<em>/g, '<em style="font-style: normal; color: #f472b6; font-weight: bold;">')
491+
: '';
492+
const hierarchy_lvl4 = hit._formatted?.hierarchy_lvl4
493+
? hit._formatted.hierarchy_lvl4.replace(/<em>/g, '<em style="font-style: normal; color: #f472b6; font-weight: bold;">')
494+
: '';
495+
const hierarchy_lvl5 = hit._formatted?.hierarchy_lvl5
496+
? hit._formatted.hierarchy_lvl5.replace(/<em>/g, '<em style="font-style: normal; color: #f472b6; font-weight: bold;">')
497+
: '';
498+
const content = hit._formatted?.content
499+
? hit._formatted.content.replace(/<em>/g, '<em style="font-style: normal; color: #f472b6; font-weight: bold;">')
500+
: '';
501+
483502
let title = '';
484-
if (hit.hierarchy_lvl1) {
485-
title = hit.hierarchy_lvl1;
486-
if (hit.hierarchy_lvl2) {
487-
title += ' > ' + hit.hierarchy_lvl2;
488-
if (hit.hierarchy_lvl3) {
489-
title += ' > ' + hit.hierarchy_lvl3;
490-
if (hit.hierarchy_lvl4) {
491-
title += ' > ' + hit.hierarchy_lvl4;
492-
if (hit.hierarchy_lvl5) {
493-
title += ' > ' + hit.hierarchy_lvl5;
503+
if (hierarchy_lvl1) {
504+
title = hierarchy_lvl1;
505+
if (hierarchy_lvl2) {
506+
title += ' > ' + hierarchy_lvl2;
507+
if (hierarchy_lvl3) {
508+
title += ' > ' + hierarchy_lvl3;
509+
if (hierarchy_lvl4) {
510+
title += ' > ' + hierarchy_lvl4;
511+
if (hierarchy_lvl5) {
512+
title += ' > ' + hierarchy_lvl5;
494513
}
495514
}
496515
}
497516
}
498517
}
499-
500-
const content = hit._formatted?.content
501-
? hit._formatted.content.replace(/<em>/g, '<em style="font-style: normal; color: #f472b6; font-weight: bold;">')
502-
: '';
503518

504519
resultItem.innerHTML = `
505520
<div style="font-weight: 500; margin-bottom: 4px;">${title}</div>

0 commit comments

Comments
 (0)