@@ -304,10 +304,12 @@ const Search = {
304304 if ( title . toLowerCase ( ) . trim ( ) . includes ( queryLower ) && ( queryLower . length >= title . length / 2 ) ) {
305305 for ( const [ file , id ] of foundTitles ) {
306306 let score = Math . round ( 100 * queryLower . length / title . length )
307+ let isDocumentTitle = titles [ file ] === title
308+ let sectionId = id ? "#" + id : ""
307309 results . push ( [
308310 docNames [ file ] ,
309- titles [ file ] !== title ? `${ titles [ file ] } > ${ title } ` : title ,
310- id !== null ? "#" + id : "" ,
311+ isDocumentTitle ? title : `${ titles [ file ] } > ${ title } ` ,
312+ isDocumentTitle ? "" : sectionId , // don't use the section id if we matched on the exact document title (creates duplicates below)
311313 null ,
312314 score ,
313315 filenames [ file ] ,
@@ -362,14 +364,12 @@ const Search = {
362364
363365 // remove duplicate search results
364366 // note the reversing of results, so that in the case of duplicates, the highest-scoring entry is kept
365- // this may remove some entries which refer to slightly different parts of the same document
366- // but this is a tradeoff to avoid showing the same document multiple times (the preview always looks the
367- // same, so this is not very useful)
368367 let seen = new Set ( ) ;
369368 results = results . reverse ( ) . reduce ( ( acc , result ) => {
370- if ( ! seen . has ( result [ 0 ] ) ) {
369+ let resultStr = result . slice ( 0 , 4 ) . concat ( [ result [ 5 ] ] ) . map ( v => String ( v ) ) . join ( ',' ) ;
370+ if ( ! seen . has ( resultStr ) ) {
371371 acc . push ( result ) ;
372- seen . add ( result [ 0 ] ) ;
372+ seen . add ( resultStr ) ;
373373 }
374374 return acc ;
375375 } , [ ] ) ;
0 commit comments