Skip to content

Commit

Permalink
Account for partial string matches in fetchLinkSuggestions (#62570)
Browse files Browse the repository at this point in the history
Co-authored-by: noisysocks <noisysocks@git.wordpress.org>
Co-authored-by: andrewserong <andrewserong@git.wordpress.org>
  • Loading branch information
3 people authored Jun 17, 2024
1 parent aa6b6f0 commit 4413591
Showing 1 changed file with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

1 comment on commit 4413591

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected in 4413591.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/9539966136
📝 Reported issues:

Please sign in to comment.