Skip to content

Commit 3a5e970

Browse files
committed
adding 3 results to show for homepage variant
1 parent 41ea30e commit 3a5e970

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

blocks/doc-search/doc-search.js

+19-19
Original file line numberDiff line numberDiff line change
@@ -238,19 +238,19 @@ export function displayResults(matches, terms, container, isHomepage) {
238238
* @param {Array} terms - Array of search terms to highlight.
239239
* @param {HTMLElement} container - Results container.
240240
*/
241-
export function displayResult(match, terms, container, isHomepage) {
242-
// reset display
243-
container.setAttribute('aria-hidden', false);
244-
container.querySelector('.doc-search-no-result').setAttribute('aria-hidden', true);
245-
const li = buildResult(match, terms, isHomepage);
246-
if (li) {
247-
container.append(li);
248-
container.classList.add('open');
249-
if (!isHomepage) container.closest('aside').classList.add('expand');
250-
} else {
251-
displayNoResults(container, isHomepage);
252-
}
253-
}
241+
// export function displayResult(match, terms, container, isHomepage) {
242+
// // reset display
243+
// container.setAttribute('aria-hidden', false);
244+
// container.querySelector('.doc-search-no-result').setAttribute('aria-hidden', true);
245+
// const li = buildResult(match, terms, isHomepage);
246+
// if (li) {
247+
// container.append(li);
248+
// container.classList.add('open');
249+
// if (!isHomepage) container.closest('aside').classList.add('expand');
250+
// } else {
251+
// displayNoResults(container, isHomepage);
252+
// }
253+
// }
254254

255255
/**
256256
* Hides the search results container.
@@ -293,7 +293,7 @@ function findDoc(query, docs = [], findMultiple = false) {
293293
docs.forEach((doc) => (doc.title ? indexDocs.push(doc) : faqDocs.push(doc)));
294294

295295
// split the query into terms, trimming and filtering out 1-2 letter and unhelpful words
296-
const filterOut = ['and', 'but', 'can', 'eds', 'for', 'how', 'the', 'use', 'what'];
296+
const filterOut = ['and', 'but', 'can', 'eds', 'for', 'how', 'the', 'use', 'what', 'aem'];
297297
const terms = query.toLowerCase().split(' ').map((e) => e.trim()).filter((e) => e.length > 2 && !filterOut.includes(e));
298298
if (!terms.length) return { terms, match: [] }; // eject if no valid search terms
299299

@@ -313,8 +313,8 @@ function findDoc(query, docs = [], findMultiple = false) {
313313
perfectMatches.add(createSearchResultObject(doc, terms, 'faq'));
314314
}
315315
});
316-
// eject if we have and only need one result
317-
if (!findMultiple && perfectMatches.size > 3) return { terms, match: [...perfectMatches] };
316+
// eject if we have 3 results at least to show
317+
if (!findMultiple && perfectMatches.size >= 3) return { terms, match: [...perfectMatches] };
318318

319319
// find strong matches (some terms match title or faq question)
320320
indexDocs.forEach((doc) => {
@@ -327,8 +327,8 @@ function findDoc(query, docs = [], findMultiple = false) {
327327
strongMatches.add(createSearchResultObject(doc, terms, 'faq'));
328328
}
329329
});
330-
// eject if we have and only need one result
331-
if (!findMultiple && strongMatches.size > 3) return { terms, match: [...strongMatches] };
330+
// eject if we have 3 results at least to show
331+
if (!findMultiple && (perfectMatches.size + strongMatches.size) >= 3) return { terms, match: [...strongMatches] };
332332

333333
// find weaker/fallback matches (some terms match content or faq answer}
334334
indexDocs.forEach((doc) => {
@@ -372,7 +372,7 @@ function searchQuery(search, docs, results, isHomepage) {
372372
? [...new Map(match.map((item) => [item.path, item])).values()]
373373
: match;
374374
if (isHomepage) {
375-
displayResult(uniqueMatches[0], terms, results, isHomepage);
375+
displayResults(uniqueMatches.slice(0, 3), terms, results, isHomepage);
376376
} else {
377377
displayResults(uniqueMatches, terms, results, isHomepage);
378378
}

0 commit comments

Comments
 (0)