From 4413591a680e1e63fb56cbadf9878eb48a951a5e Mon Sep 17 00:00:00 2001 From: Robert Anderson Date: Mon, 17 Jun 2024 10:19:09 +1000 Subject: [PATCH] Account for partial string matches in fetchLinkSuggestions (#62570) Co-authored-by: noisysocks Co-authored-by: andrewserong --- .../src/fetch/__experimental-fetch-link-suggestions.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/core-data/src/fetch/__experimental-fetch-link-suggestions.ts b/packages/core-data/src/fetch/__experimental-fetch-link-suggestions.ts index 024a5931abbd8..e1a166ee272db 100644 --- a/packages/core-data/src/fetch/__experimental-fetch-link-suggestions.ts +++ b/packages/core-data/src/fetch/__experimental-fetch-link-suggestions.ts @@ -264,14 +264,16 @@ export default async function fetchLinkSuggestions( * @param search */ export function sortResults( results: SearchResult[], search: string ) { - const searchTokens = new Set( tokenize( search ) ); + const searchTokens = tokenize( search ); const scores = {}; for ( const result of results ) { if ( result.title ) { const titleTokens = tokenize( result.title ); - const matchingTokens = titleTokens.filter( ( token ) => - searchTokens.has( token ) + const matchingTokens = titleTokens.filter( ( titleToken ) => + searchTokens.some( ( searchToken ) => + titleToken.includes( searchToken ) + ) ); scores[ result.id ] = matchingTokens.length / titleTokens.length; } else {