Skip to content

Commit

Permalink
Clarify documentation around default scoring/ranking algorithm. (#79)
Browse files Browse the repository at this point in the history
  • Loading branch information
lfrancke authored Jul 15, 2024
1 parent 0ebd710 commit 88450c5
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,13 @@ Render this to show the command menu inline, or use [Dialog](#dialog-cmdk-dialog
</Command.Root>
```

By default, this uses a scoring algorithm to filter and rank items based on the user's search input.
The algorithm takes into account various factors like continuous matches, word and character jumps among other things.

You can provide a custom `filter` function that is called to rank each item. Both strings are normalized as lowercase and trimmed.

The following example implements a strict substring match:

```svelte
<Command.Root
filter={(value, search) => {
Expand All @@ -107,6 +112,8 @@ You can provide a custom `filter` function that is called to rank each item. Bot
/>
```

In this strict substring match example, the filter function returns a score of 1 if the item's value contains the search string as a substring, and 0 otherwise, removing it from the result list.

Or disable filtering and sorting entirely:

```svelte
Expand Down

0 comments on commit 88450c5

Please sign in to comment.