@@ -344,6 +344,11 @@ interface WeightedSearchField {
344344interface SearchFieldsMatch {
345345 /** Roughly 0.3 (inside a word) to 1.5 (exact title). */
346346 readonly quality : number ;
347+ /**
348+ * Every non-filler token has three or more characters and matched a whole word at full
349+ * weight, before phrase bonuses. Optional filler words don't count either way.
350+ */
351+ readonly wholeWords : boolean ;
347352 /** Every token matched at a word start, without a typo. */
348353 readonly strong : boolean ;
349354 /** Source ranges matched in the first field, for highlighting. */
@@ -407,6 +412,7 @@ function matchSearchFields(
407412 const primaryRanges : SearchRange [ ] = [ ] ;
408413 let total = 0 ;
409414 let counted = 0 ;
415+ let notWhole = false ;
410416 let strong = true ;
411417 for ( const token of tokens ) {
412418 let best = 0 ;
@@ -433,6 +439,9 @@ function matchSearchFields(
433439 if ( bestPrimary ) primaryRanges . push ( ...( bestPrimary . letters ?? [ bestPrimary ] ) ) ;
434440 total += best ;
435441 counted += 1 ;
442+ // Optional filler never decides the whole-word tier; a query of only filler never earns it.
443+ if ( FILLER_WORDS . has ( token ) ) notWhole ||= ! fillerOptional ;
444+ else notWhole ||= token . length < PICK_PREFIX_MIN_LENGTH || best < WHOLE_WORD ;
436445 }
437446 let quality = total / counted ;
438447 if ( primary ) {
@@ -441,6 +450,7 @@ function matchSearchFields(
441450 }
442451 return {
443452 quality,
453+ wholeWords : ! notWhole ,
444454 strong,
445455 primaryRanges : mergeRanges ( primaryRanges ) ,
446456 } ;
@@ -851,7 +861,7 @@ function matchReference(
851861 } ;
852862 return ( thread . id && matches ( thread . id ) ) ||
853863 thread . pullRequests ?. some ( ( pullRequest ) => pullRequest . references ?. some ( matches ) )
854- ? { quality : 0.6 , strong : true , primaryRanges : [ ] }
864+ ? { quality : 0.6 , wholeWords : false , strong : true , primaryRanges : [ ] }
855865 : null ;
856866}
857867
@@ -888,6 +898,7 @@ export interface ThreadSearchMatch {
888898 readonly score : number ;
889899 /** Match quality alone; see `rankSearchGroups`. */
890900 readonly quality : number ;
901+ readonly wholeWords : boolean ;
891902 /** Every token matched at a word start; see `rankSearchGroups`. */
892903 readonly strong : boolean ;
893904 /** Matched ranges in the title. */
@@ -1043,6 +1054,7 @@ export function scoreThreadSearch(
10431054 return {
10441055 score : match . quality * threadUsageBoost ( thread , now ) ,
10451056 quality : match . quality ,
1057+ wholeWords : match . wholeWords ,
10461058 // A thread's whole title never lifts its group over a command or project
10471059 // of that name: every new thread is titled "New thread" for a while.
10481060 groupQuality : Math . min ( match . quality , WHOLE_NAME - 0.01 ) ,
@@ -1146,6 +1158,7 @@ export function rankSearchGroups<
11461158 readonly pickedAt ?: number ;
11471159 readonly pickedExactly ?: boolean ;
11481160 readonly groupQuality ?: number ;
1161+ readonly wholeWords ?: boolean ;
11491162 } ,
11501163> (
11511164 groups : ReadonlyArray < { readonly group : G ; readonly items : ReadonlyArray < T > } > ,
@@ -1173,12 +1186,15 @@ export function rankSearchGroups<
11731186 // A longer-query pick must not pass a whole-name match for the current query.
11741187 const wordMatch = ( match : M ) => Math . min ( matchClass ( match . quality ) , 2 ) ;
11751188 const exactPickAt = ( match : M ) => ( match . pickedExactly ? ( match . pickedAt ?? 0 ) : 0 ) ;
1189+ // Use reorders whole words or prefixes among themselves, never a prefix above a whole word.
1190+ const wholeWord = ( match : M ) => Number ( match . wholeWords ?? match . quality >= WHOLE_WORD ) ;
11761191 const sorted = [ ...items ] . sort (
11771192 ( left , right ) =>
11781193 wordMatch ( right . match ) - wordMatch ( left . match ) ||
11791194 exactPickAt ( right . match ) - exactPickAt ( left . match ) ||
11801195 matchClass ( right . match . quality ) - matchClass ( left . match . quality ) ||
11811196 ( right . match . pickedAt ?? 0 ) - ( left . match . pickedAt ?? 0 ) ||
1197+ wholeWord ( right . match ) - wholeWord ( left . match ) ||
11821198 right . match . score - left . match . score ,
11831199 ) ;
11841200 const best = Math . max (
0 commit comments