@@ -238,19 +238,19 @@ export function displayResults(matches, terms, container, isHomepage) {
238
238
* @param {Array } terms - Array of search terms to highlight.
239
239
* @param {HTMLElement } container - Results container.
240
240
*/
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
+ // }
254
254
255
255
/**
256
256
* Hides the search results container.
@@ -293,7 +293,7 @@ function findDoc(query, docs = [], findMultiple = false) {
293
293
docs . forEach ( ( doc ) => ( doc . title ? indexDocs . push ( doc ) : faqDocs . push ( doc ) ) ) ;
294
294
295
295
// 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' ] ;
297
297
const terms = query . toLowerCase ( ) . split ( ' ' ) . map ( ( e ) => e . trim ( ) ) . filter ( ( e ) => e . length > 2 && ! filterOut . includes ( e ) ) ;
298
298
if ( ! terms . length ) return { terms, match : [ ] } ; // eject if no valid search terms
299
299
@@ -313,8 +313,8 @@ function findDoc(query, docs = [], findMultiple = false) {
313
313
perfectMatches . add ( createSearchResultObject ( doc , terms , 'faq' ) ) ;
314
314
}
315
315
} ) ;
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 ] } ;
318
318
319
319
// find strong matches (some terms match title or faq question)
320
320
indexDocs . forEach ( ( doc ) => {
@@ -327,8 +327,8 @@ function findDoc(query, docs = [], findMultiple = false) {
327
327
strongMatches . add ( createSearchResultObject ( doc , terms , 'faq' ) ) ;
328
328
}
329
329
} ) ;
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 ] } ;
332
332
333
333
// find weaker/fallback matches (some terms match content or faq answer }
334
334
indexDocs . forEach ( ( doc ) => {
@@ -372,7 +372,7 @@ function searchQuery(search, docs, results, isHomepage) {
372
372
? [ ...new Map ( match . map ( ( item ) => [ item . path , item ] ) ) . values ( ) ]
373
373
: match ;
374
374
if ( isHomepage ) {
375
- displayResult ( uniqueMatches [ 0 ] , terms , results , isHomepage ) ;
375
+ displayResults ( uniqueMatches . slice ( 0 , 3 ) , terms , results , isHomepage ) ;
376
376
} else {
377
377
displayResults ( uniqueMatches , terms , results , isHomepage ) ;
378
378
}
0 commit comments