Skip to content

Commit 75182da

Browse files
committed
fix(cli): cap and score-filter module search results
1 parent ff0cc23 commit 75182da

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

  • packages/nuxt-cli/src/commands/module

packages/nuxt-cli/src/commands/module/search.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,15 @@ import { checkNuxtCompatibility, fetchModules, MODULES_API_URL } from './_utils'
1515

1616
const DASH_RE = /-/g
1717

18+
/**
19+
* Every result is rendered as its own box, so a query that happens to be a
20+
* subsequence of half the registry (`stripe` matches 178 of 316 modules at any
21+
* score) must not turn into a screenful of boxes. The score cut removes the
22+
* incidental matches and the limit caps what is left.
23+
*/
24+
const SCORE_THRESHOLD = 0.5
25+
const RESULT_LIMIT = 20
26+
1827
const { format: formatNumber } = new Intl.NumberFormat('en-GB', {
1928
notation: 'compact',
2029
maximumFractionDigits: 1,
@@ -77,7 +86,12 @@ async function findModuleByKeywords(query: string, nuxtVersion: string) {
7786
].filter(Boolean).join(' ')),
7887
}))
7988

80-
const results = fuzzysort.go(query, targets, { keys: ['name', 'npm', 'rest'], all: !query }).map(({ obj: { item } }) => {
89+
const results = fuzzysort.go(query, targets, {
90+
keys: ['name', 'npm', 'rest'],
91+
all: !query,
92+
threshold: SCORE_THRESHOLD,
93+
limit: RESULT_LIMIT,
94+
}).map(({ obj: { item } }) => {
8195
const res: Record<string, string> = {
8296
name: item.name,
8397
package: item.npm,

0 commit comments

Comments
 (0)