@@ -15,6 +15,7 @@ import {
1515 partitionPullRequestsWithPriority ,
1616 pullRequestEntryKey ,
1717 pullRequestEntryViewer ,
18+ rankPullRequestMatches ,
1819 type EnvironmentPullRequestEntry ,
1920 type PullRequestPartitionsSnapshot ,
2021} from "./pullRequestList.logic" ;
@@ -25,6 +26,7 @@ export const pullRequestListEntryId = (target: Parameters<typeof pullRequestSurf
2526/** The held rows narrowed to what the reader asked for, in the groups the list shows. */
2627export function pullRequestGroups ( {
2728 known,
29+ baseline,
2830 providers,
2931 viewers,
3032 involvement,
@@ -39,6 +41,8 @@ export function pullRequestGroups({
3941 partitionsWanted,
4042} : {
4143 known : ReadonlyArray < EnvironmentPullRequestEntry > ;
44+ /** The text-free rows already loaded, or undefined when the typed filters cannot vet them. */
45+ baseline : ReadonlyArray < EnvironmentPullRequestEntry > | undefined ;
4246 providers : PullRequestListResult [ "providers" ] ;
4347 viewers : PullRequestListResult [ "viewers" ] ;
4448 involvement : PullRequestInvolvement ;
@@ -56,22 +60,33 @@ export function pullRequestGroups({
5660 providers . flatMap ( ( provider ) => ( provider . searchesOnHost ? [ provider . host ] : [ ] ) ) ,
5761 ) ;
5862
59- const entries = ( ( ) => {
60- const involvementEntries = filterPullRequestsByInvolvement ( known , viewers , involvement ) ;
61- // Host text searches cover fields absent from rows, so do not narrow their matches locally.
62- // Filter text locally while results are pending or when the host has no text search.
63- const narrowedEntries = hasLocalFilters
63+ const narrowRows = ( rows : ReadonlyArray < EnvironmentPullRequestEntry > ) => {
64+ const involvementEntries = filterPullRequestsByInvolvement ( rows , viewers , involvement ) ;
65+ return hasLocalFilters
6466 ? involvementEntries . filter ( ( entry ) =>
6567 matchesPullRequestFilters ( entry , localFilters , pullRequestEntryViewer ( entry , viewers ) ) ,
6668 )
6769 : involvementEntries ;
70+ } ;
71+
72+ const entries = ( ( ) => {
73+ const narrowedEntries = narrowRows ( known ) ;
6874 if ( text . length === 0 ) {
6975 return narrowedEntries . toSorted ( comparePullRequestsByRecency ) ;
7076 }
71- return narrowedEntries . filter (
77+ // Host text searches cover fields absent from rows, so do not narrow their matches locally.
78+ // Filter text locally while results are pending or when the host has no text search.
79+ const matched = narrowedEntries . filter (
7280 ( entry ) =>
7381 ( answeredLocally && searchingHosts . has ( entry . host ) ) || matchesPullRequestQuery ( entry , text ) ,
7482 ) ;
83+ // Host search matches whole words, so it can miss loaded rows a partial word matches here.
84+ // Those follow the host's ranked answer rather than reshuffling it.
85+ const listed = new Set ( matched . map ( pullRequestEntryKey ) ) ;
86+ const missed = narrowRows ( baseline ?? [ ] ) . filter (
87+ ( entry ) => ! listed . has ( pullRequestEntryKey ( entry ) ) && matchesPullRequestQuery ( entry , text ) ,
88+ ) ;
89+ return missed . length === 0 ? matched : [ ...matched , ...rankPullRequestMatches ( missed , text ) ] ;
7590 } ) ( ) ;
7691
7792 const listedPullRequestTabStatuses : Record < string , PullRequestTabStatusSeed > = Object . fromEntries (
0 commit comments