@astryxdesign/cli 0.7.2-canary.6d4f178 → 0.7.2-canary.72db6f9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +74 -73
- package/api/build/help/help.mjs +1 -1
- package/api/component/_adapter.d.mts +31 -0
- package/api/component/_adapter.mjs +116 -0
- package/api/component/component.mjs +60 -10
- package/api/component/doc-links.test.mjs +386 -0
- package/api/discover/_adapter.d.mts +119 -12
- package/api/discover/_adapter.mjs +449 -10
- package/api/discover/_adapter.test.mjs +599 -17
- package/api/discover/_catalog-view.d.mts +16 -5
- package/api/discover/_catalog-view.mjs +32 -8
- package/api/discover/detail/doc/doc.mjs +9 -1
- package/api/discover/discover.d.mts +11 -0
- package/api/discover/discover.doc.mjs +7 -6
- package/api/discover/discover.mjs +107 -19
- package/api/discover/discover.type.d.mts +18 -7
- package/api/discover/discover.type.mjs +15 -7
- package/api/discover/list/list.d.mts +4 -3
- package/api/discover/list/list.mjs +17 -10
- package/api/docs/_adapter.d.mts +74 -0
- package/api/docs/_adapter.mjs +550 -14
- package/api/docs/integration-tree.test.mjs +22 -0
- package/api/docs/integrationDocs.test.mjs +124 -0
- package/api/docs/list/list.mjs +12 -2
- package/api/doctor/doctor.mjs +27 -3
- package/api/doctor/doctor.test.mjs +43 -0
- package/api/doctor/theme-checks.mjs +1 -1
- package/api/doctor/theme-checks.test.mjs +136 -0
- package/api/gap-report/gap-report.d.mts +3 -0
- package/api/gap-report/gap-report.doc.mjs +11 -3
- package/api/gap-report/gap-report.mjs +152 -48
- package/api/gap-report/gap-report.test.mjs +233 -0
- package/api/gap-report/gap-report.type.d.mts +41 -0
- package/api/gap-report/gap-report.type.mjs +18 -0
- package/api/index.d.mts +2 -0
- package/api/index.mjs +2 -0
- package/api/init/run/run.mjs +2 -2
- package/api/integration/_adapter.d.mts +45 -0
- package/api/integration/_adapter.mjs +112 -0
- package/api/integration/add-contribution.mjs +1 -1
- package/api/integration/add-contribution.test.mjs +4 -2
- package/api/integration/authoring-checks.mjs +108 -4
- package/api/integration/authoring-checks.test.mjs +808 -0
- package/api/integration/authoring-checks.type.d.mts +143 -0
- package/api/integration/authoring-checks.type.mjs +74 -2
- package/api/integration/check/check.d.mts +96 -0
- package/api/integration/check/check.mjs +357 -0
- package/api/integration/check/check.test.mjs +489 -0
- package/api/integration/integration-check.type.d.mts +118 -0
- package/api/integration/integration-check.type.mjs +84 -0
- package/api/integration/integrationCheck.doc.d.mts +10 -0
- package/api/integration/integrationCheck.doc.mjs +73 -0
- package/api/integration/integrationComponentConflicts.doc.mjs +45 -6
- package/api/integration/integrationDocConflicts.doc.mjs +22 -5
- package/api/integration/pack-check.mjs +296 -7
- package/api/integration/pack-check.test.mjs +367 -0
- package/api/integration/validate-integration-fixes.test.mjs +67 -0
- package/api/integration/validate-integration.mjs +36 -3
- package/api/integration/validate-integration.test.mjs +88 -8
- package/api/integration/validate-integration.type.d.mts +8 -0
- package/api/integration/validate-integration.type.mjs +12 -1
- package/api/integration/validateIntegration.doc.mjs +19 -3
- package/api/search/search.d.mts +72 -12
- package/api/search/search.domain-priority.test.mjs +108 -18
- package/api/search/search.integration-check.test.mjs +24 -0
- package/api/search/search.mjs +503 -38
- package/api/search/search.test.mjs +139 -0
- package/api/theme/build/build.family.test.mjs +54 -6
- package/api/theme/build/build.mjs +114 -17
- package/api/theme/themeBuild.doc.mjs +4 -4
- package/api/upgrade/_adapter.d.mts +40 -2
- package/api/upgrade/_adapter.mjs +117 -4
- package/api/upgrade/run/cli-behind-core.test.mjs +438 -0
- package/api/upgrade/run/run.mjs +30 -1
- package/api/upgrade/status/status.d.mts +21 -5
- package/api/upgrade/status/status.mjs +45 -8
- package/api/upgrade/upgrade.doc.mjs +5 -3
- package/api/upgrade/upgrade.type.d.mts +23 -0
- package/api/upgrade/upgrade.type.mjs +16 -1
- package/assets/codemods/runner.mjs +7 -1
- package/assets/discover/official-packages.json +367 -0
- package/assets/docs/README.md +10 -0
- package/assets/docs/author-a-theme.doc.mjs +3 -3
- package/assets/docs/browser-support.doc.mjs +1 -1
- package/assets/docs/getting-started.doc.mjs +3 -3
- package/assets/docs/styling-overview.doc.mjs +1 -1
- package/assets/docs/theme.doc.dense.mjs +1 -1
- package/assets/docs/theme.doc.mjs +2 -2
- package/assets/docs/theme.doc.zh.mjs +1 -1
- package/assets/docs/tree/add-a-component.doc.mjs +1 -1
- package/assets/docs/tree/add-a-theme.doc.mjs +1 -1
- package/assets/docs/tree/add-a-topic.doc.mjs +11 -8
- package/assets/docs/tree/agent-guidance.doc.mjs +2 -2
- package/assets/docs/tree/block-template.doc.mjs +8 -20
- package/assets/docs/tree/build-the-template.doc.mjs +1 -1
- package/assets/docs/tree/check-the-props.doc.mjs +201 -0
- package/assets/docs/tree/check-your-docs.doc.mjs +65 -7
- package/assets/docs/tree/checks.doc.mjs +25 -17
- package/assets/docs/tree/codemods.doc.mjs +4 -4
- package/assets/docs/tree/component-family.doc.mjs +3 -5
- package/assets/docs/tree/component-imports.doc.mjs +2 -2
- package/assets/docs/tree/components.doc.mjs +1 -1
- package/assets/docs/tree/debug-and-gap-reports.doc.mjs +30 -21
- package/assets/docs/tree/define-the-theme.doc.mjs +6 -5
- package/assets/docs/tree/describe-the-component.doc.mjs +2 -2
- package/assets/docs/tree/docs.doc.mjs +3 -3
- package/assets/docs/tree/document-the-template.doc.mjs +1 -1
- package/assets/docs/tree/document-the-theme.doc.mjs +3 -3
- package/assets/docs/tree/export-template-assets.doc.mjs +1 -1
- package/assets/docs/tree/extend-or-replace.doc.mjs +6 -6
- package/assets/docs/tree/fonts-and-assets.doc.mjs +2 -2
- package/assets/docs/tree/generate-a-palette.doc.mjs +5 -3
- package/assets/docs/tree/grade-template-with-agent.doc.mjs +1 -1
- package/assets/docs/tree/integrations.doc.mjs +8 -0
- package/assets/docs/tree/layout-spacing.doc.mjs +2 -3
- package/assets/docs/tree/layout.doc.mjs +6 -6
- package/assets/docs/tree/links.doc.mjs +6 -5
- package/assets/docs/tree/migration-setup.doc.mjs +3 -2
- package/assets/docs/tree/migration-verification.doc.mjs +0 -1
- package/assets/docs/tree/migration.doc.mjs +0 -1
- package/assets/docs/tree/package-and-test.doc.mjs +1 -1
- package/assets/docs/tree/page-template.doc.mjs +4 -8
- package/assets/docs/tree/publishing.doc.mjs +4 -4
- package/assets/docs/tree/quick-start.doc.mjs +38 -22
- package/assets/docs/tree/replace-a-core-component.doc.mjs +4 -6
- package/assets/docs/tree/replace-a-core-template.doc.mjs +6 -8
- package/assets/docs/tree/sections-and-placement.doc.mjs +6 -8
- package/assets/docs/tree/see-it-in-an-app.doc.mjs +4 -2
- package/assets/docs/tree/short-and-findable.doc.mjs +6 -5
- package/assets/docs/tree/single-component.doc.mjs +14 -5
- package/assets/docs/tree/start-a-template.doc.mjs +3 -3
- package/assets/docs/tree/subcomponent.doc.mjs +6 -6
- package/assets/docs/tree/template-assets.doc.mjs +2 -2
- package/assets/docs/tree/template-doc-overview.doc.mjs +5 -16
- package/assets/docs/tree/template-fonts.doc.mjs +1 -1
- package/assets/docs/tree/template-icons.doc.mjs +1 -1
- package/assets/docs/tree/template-images-media.doc.mjs +1 -1
- package/assets/docs/tree/template-styles.doc.mjs +2 -2
- package/assets/docs/tree/templates.doc.mjs +1 -1
- package/assets/docs/tree/test-in-an-app.doc.mjs +3 -3
- package/assets/docs/tree/test-template-in-app.doc.mjs +1 -1
- package/assets/docs/tree/tokens-and-setup.doc.mjs +19 -15
- package/assets/docs/tree/troubleshooting.doc.mjs +8 -8
- package/assets/docs/tree/type-scale.doc.mjs +3 -3
- package/assets/docs/tree/upgrading.doc.mjs +4 -4
- package/assets/docs/tree/use-a-theme-in-an-app.doc.mjs +3 -1
- package/assets/docs/tree/verify-packed-template.doc.mjs +1 -1
- package/assets/docs/tree/versioning.doc.mjs +6 -6
- package/assets/docs/tree/write-the-template-file.doc.mjs +4 -3
- package/assets/docs/use-a-theme.doc.mjs +2 -2
- package/assets/theme.template.ts +1 -1
- package/authoring/codemod/codemod.doc.mjs +7 -3
- package/authoring/config/config.doc.mjs +9 -6
- package/authoring/config/type.ts +4 -2
- package/authoring/discover/discover.doc.mjs +1 -1
- package/authoring/doctypes/base/graph-fields.doc.mjs +6 -4
- package/authoring/doctypes/command/command.doc.mjs +14 -12
- package/authoring/doctypes/component/component.doc.mjs +29 -26
- package/authoring/doctypes/component/type.ts +15 -5
- package/authoring/doctypes/enum/enum.doc.mjs +7 -4
- package/authoring/doctypes/function/function.doc.mjs +9 -8
- package/authoring/doctypes/hook/hook.doc.mjs +5 -4
- package/authoring/doctypes/hook/type.ts +4 -0
- package/authoring/doctypes/namespace/namespace.doc.mjs +7 -6
- package/authoring/doctypes/reference/reference.doc.mjs +11 -10
- package/authoring/doctypes/schema/schema.doc.mjs +9 -9
- package/authoring/doctypes/template/integration-template.doc.d.mts +11 -0
- package/authoring/doctypes/template/integration-template.doc.mjs +49 -0
- package/authoring/doctypes/template/parse.d.mts +6 -2
- package/authoring/doctypes/template/parse.mjs +3 -1
- package/authoring/doctypes/template/template.doc.mjs +3 -3
- package/authoring/doctypes/template/type.ts +22 -0
- package/authoring/doctypes/theme/theme.doc.mjs +2 -2
- package/authoring/gap-report/gap-report.doc.mjs +2 -2
- package/authoring/identity/identity.doc.mjs +3 -3
- package/authoring/index.d.ts +1 -0
- package/authoring/integration/integration.doc.mjs +12 -4
- package/authoring/integration/parse.test.mjs +10 -0
- package/authoring/integration/schema.d.mts +2 -0
- package/authoring/integration/schema.mjs +1 -0
- package/authoring/integration/type.ts +4 -0
- package/clients/cli/commands/build-theme.batch-report.test.mjs +3 -1
- package/clients/cli/commands/build-theme.mjs +1 -1
- package/clients/cli/commands/build-theme.path-safety.test.mjs +155 -21
- package/clients/cli/commands/cli-postinstall.test.mjs +49 -1
- package/clients/cli/commands/discover.broken-integration.test.mjs +4 -1
- package/clients/cli/commands/discover.doc.mjs +1 -1
- package/clients/cli/commands/discover.mjs +144 -93
- package/clients/cli/commands/discover.no-source.test.mjs +447 -33
- package/clients/cli/commands/discover.sources.test.mjs +20 -1
- package/clients/cli/commands/doctor-integration-components.doc.mjs +18 -4
- package/clients/cli/commands/doctor-integration-docs.doc.mjs +19 -5
- package/clients/cli/commands/doctor-integration-validate.doc.mjs +13 -2
- package/clients/cli/commands/doctor-integration.test.mjs +884 -0
- package/clients/cli/commands/doctor.mjs +281 -5
- package/clients/cli/commands/gap-report.doc.mjs +14 -2
- package/clients/cli/commands/gap-report.mjs +24 -2
- package/clients/cli/commands/gap-report.test.mjs +79 -0
- package/clients/cli/commands/integration-authoring.test.mjs +46 -0
- package/clients/cli/commands/integration-check.doc.mjs +85 -0
- package/clients/cli/commands/integration-check.test.mjs +411 -0
- package/clients/cli/commands/integration.doc.mjs +6 -2
- package/clients/cli/commands/integration.mjs +116 -5
- package/clients/cli/commands/json-contract.test.mjs +5 -1
- package/clients/cli/commands/setup-nudge.test.mjs +79 -1
- package/clients/cli/commands/swizzle.mjs +5 -3
- package/clients/cli/commands/swizzle.routing.test.mjs +18 -1
- package/clients/cli/commands/text-json-parity.test.mjs +5 -0
- package/clients/cli/commands/theme-build.doc.mjs +2 -2
- package/clients/cli/commands/upgrade.doc.mjs +14 -0
- package/clients/cli/commands/upgrade.older-cli.test.mjs +160 -0
- package/clients/cli/index.mjs +30 -5
- package/foundation/agent-docs/agent-doc-state.d.mts +14 -0
- package/foundation/agent-docs/agent-doc-state.mjs +38 -0
- package/foundation/agent-docs/agent-docs.d.mts +2 -1
- package/foundation/agent-docs/agent-docs.mjs +8 -6
- package/foundation/config/project.mjs +82 -0
- package/foundation/discovery/authoring-self-docs.mjs +2 -1
- package/foundation/discovery/component-discovery.d.mts +18 -0
- package/foundation/discovery/component-discovery.mjs +2 -2
- package/foundation/discovery/copied-passages.d.mts +216 -0
- package/foundation/discovery/copied-passages.mjs +720 -0
- package/foundation/discovery/copied-passages.test.mjs +124 -0
- package/foundation/discovery/doc-consistency.d.mts +34 -0
- package/foundation/discovery/doc-consistency.mjs +513 -0
- package/foundation/discovery/doc-consistency.test.mjs +347 -0
- package/foundation/discovery/doc-fluff.d.mts +112 -0
- package/foundation/discovery/doc-fluff.mjs +328 -0
- package/foundation/discovery/doc-fluff.test.mjs +142 -0
- package/foundation/discovery/doc-types.d.mts +157 -0
- package/foundation/discovery/doc-types.mjs +1231 -0
- package/foundation/discovery/doc-types.test.mjs +744 -0
- package/foundation/discovery/docs-discovery.d.mts +88 -0
- package/foundation/discovery/docs-discovery.mjs +83 -2
- package/foundation/discovery/integration-doc-files.d.mts +22 -0
- package/foundation/discovery/integration-doc-files.mjs +231 -0
- package/foundation/discovery/integration-doc-files.test.mjs +246 -0
- package/foundation/discovery/package-tsconfig.d.mts +14 -0
- package/foundation/discovery/package-tsconfig.mjs +228 -0
- package/foundation/discovery/package-tsconfig.test.mjs +210 -0
- package/foundation/discovery/project-typescript.d.mts +32 -0
- package/foundation/discovery/project-typescript.mjs +89 -0
- package/foundation/discovery/prop-drift.d.mts +297 -0
- package/foundation/discovery/prop-drift.mjs +2428 -0
- package/foundation/discovery/prop-drift.test.mjs +2337 -0
- package/foundation/discovery/stray-pointers.d.mts +52 -0
- package/foundation/discovery/stray-pointers.mjs +293 -0
- package/foundation/discovery/stray-pointers.test.mjs +86 -0
- package/foundation/discovery/type-match.d.mts +53 -0
- package/foundation/discovery/type-match.mjs +660 -0
- package/foundation/discovery/type-match.test.mjs +169 -0
- package/foundation/discovery/type-text.d.mts +68 -0
- package/foundation/discovery/type-text.mjs +658 -0
- package/foundation/discovery/type-text.test.mjs +196 -0
- package/foundation/discovery/unresolved-references.d.mts +62 -0
- package/foundation/discovery/unresolved-references.mjs +790 -0
- package/foundation/discovery/unresolved-references.test.mjs +567 -0
- package/foundation/doc-compiler/doc-loads.test.mjs +26 -0
- package/foundation/doc-compiler/links.d.mts +41 -5
- package/foundation/doc-compiler/links.mjs +167 -28
- package/foundation/doc-compiler/links.test.mjs +97 -4
- package/foundation/doc-compiler/tree.mjs +30 -1
- package/foundation/doc-compiler/tree.test.mjs +7 -0
- package/foundation/env/package-manager.d.mts +32 -0
- package/foundation/env/package-manager.mjs +47 -0
- package/foundation/env/package-manager.test.mjs +194 -7
- package/foundation/fs/module-loader.d.mts +2 -1
- package/foundation/fs/module-loader.mjs +60 -4
- package/foundation/fs/module-loader.test.mjs +194 -0
- package/foundation/integrations/contribution-inventory.d.mts +11 -0
- package/foundation/integrations/contribution-inventory.mjs +50 -2
- package/foundation/integrations/issue.ts +6 -0
- package/foundation/integrations/validate-contributions.mjs +30 -1
- package/foundation/response/response-types.doc.mjs +15 -9
- package/package.json +11 -11
- package/scripts/postinstall.mjs +3 -3
package/api/search/search.mjs
CHANGED
|
@@ -57,9 +57,10 @@
|
|
|
57
57
|
* Between domains, ranking adds one rule ahead of the score: domain priority
|
|
58
58
|
* (see {@link domainPriority}). A component, hook, template, or theme whose
|
|
59
59
|
* name or keyword a query word hits ranks ahead of every doc the reader did not
|
|
60
|
-
* ask for by name or
|
|
61
|
-
*
|
|
62
|
-
* query holds,
|
|
60
|
+
* ask for by name, title, or a declared phrase, so `font size` finds `Text`
|
|
61
|
+
* before a token page whose heading holds the phrase. A doc the query names,
|
|
62
|
+
* whose title the query holds, or that declares the whole query as a keyword
|
|
63
|
+
* keeps its place.
|
|
63
64
|
*
|
|
64
65
|
* Description and guidance are separate tiers on purpose. A component's own
|
|
65
66
|
* one-line description saying "notification" is a claim about what it IS; the
|
|
@@ -128,6 +129,7 @@ import {
|
|
|
128
129
|
import {AstryxError} from '../error.mjs';
|
|
129
130
|
import {ERROR_CODES} from '../../foundation/response/error-codes.mjs';
|
|
130
131
|
import {setResultCoverage} from './coverage.mjs';
|
|
132
|
+
import {linkSearchResponse} from '../component/_adapter.mjs';
|
|
131
133
|
|
|
132
134
|
/**
|
|
133
135
|
* A search candidate gathered from one content domain. Extra underscore-
|
|
@@ -138,6 +140,9 @@ import {setResultCoverage} from './coverage.mjs';
|
|
|
138
140
|
* @property {string[]} [aliases] - Other names the candidate answers to, scored
|
|
139
141
|
* with the same name signals: a theme's display name.
|
|
140
142
|
* @property {string[]} [keywords]
|
|
143
|
+
* @property {string[]} [_declared] - A doc's own declared keywords: what its
|
|
144
|
+
* author lists in `keywords`, without the code terms and table cells its
|
|
145
|
+
* other keywords add.
|
|
141
146
|
* @property {string[]} [weakKeywords]
|
|
142
147
|
* @property {string} [description]
|
|
143
148
|
* @property {string[]} [prose]
|
|
@@ -255,9 +260,34 @@ function wordForms(w) {
|
|
|
255
260
|
if (w.length > 3 && w.endsWith('s')) forms.add(w.slice(0, -1));
|
|
256
261
|
if (w.length > 4 && w.endsWith('es')) forms.add(w.slice(0, -2));
|
|
257
262
|
if (w.length > 4 && w.endsWith('ies')) forms.add(w.slice(0, -3) + 'y');
|
|
263
|
+
// A gerund keeps its verb: "spacing" lost a final e ("space"), and
|
|
264
|
+
// "dragging" doubled a consonant ("drag"). A past participle does not: it
|
|
265
|
+
// usually describes a state ("archived notes"), not the action a catalog
|
|
266
|
+
// word names.
|
|
267
|
+
if (w.length >= 6 && w.endsWith('ing')) {
|
|
268
|
+
const base = w.slice(0, -3);
|
|
269
|
+
forms.add(base);
|
|
270
|
+
forms.add(`${base}e`);
|
|
271
|
+
if (/([b-df-hj-np-tv-z])\1$/.test(base)) forms.add(base.slice(0, -1));
|
|
272
|
+
}
|
|
258
273
|
return forms;
|
|
259
274
|
}
|
|
260
275
|
|
|
276
|
+
/**
|
|
277
|
+
* The singulars a lowercase word may have when it ends in a plural suffix:
|
|
278
|
+
* "tokens" is "token", "boxes" is "box", "entries" is "entry".
|
|
279
|
+
* @param {string} w
|
|
280
|
+
* @returns {string[]}
|
|
281
|
+
*/
|
|
282
|
+
function singulars(w) {
|
|
283
|
+
/** @type {string[]} */
|
|
284
|
+
const out = [];
|
|
285
|
+
if (w.length > 3 && w.endsWith('s')) out.push(w.slice(0, -1));
|
|
286
|
+
if (w.length > 4 && w.endsWith('es')) out.push(w.slice(0, -2));
|
|
287
|
+
if (w.length > 4 && w.endsWith('ies')) out.push(w.slice(0, -3) + 'y');
|
|
288
|
+
return out;
|
|
289
|
+
}
|
|
290
|
+
|
|
261
291
|
/**
|
|
262
292
|
* Whether two lowercase words are the same word, up to plural and stem form.
|
|
263
293
|
* @param {string} a
|
|
@@ -298,9 +328,201 @@ function wordsOf(text) {
|
|
|
298
328
|
function startsAWordOf(term, text) {
|
|
299
329
|
if (term.length < 4) return false;
|
|
300
330
|
if (term.length / String(text).length < 0.5) return false;
|
|
301
|
-
|
|
331
|
+
// The term or its singular may start the word: "tokens" starts
|
|
332
|
+
// "tokenizer" through "token". A singular needs five letters, so "stats"
|
|
333
|
+
// does not start "status".
|
|
334
|
+
const starts = [term, ...singulars(term).filter(f => f.length >= 5)];
|
|
335
|
+
return wordsOf(text).some(
|
|
336
|
+
w => starts.some(f => w.startsWith(f)) || sameWord(term, w),
|
|
337
|
+
);
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
/**
|
|
341
|
+
* A query with its camelCase and PascalCase identifiers spelled as words, so
|
|
342
|
+
* `SidebarToggle` reads "sidebar toggle" and `useTablePaginationState` "use
|
|
343
|
+
* table pagination state". Plain words, and identifiers joined with `_` or `-`, are
|
|
344
|
+
* unchanged: a joined token that matches nothing stays unmatched.
|
|
345
|
+
* @param {string} query - The query as typed, before lowercasing.
|
|
346
|
+
* @returns {string} Lowercased.
|
|
347
|
+
*/
|
|
348
|
+
export function spellIdentifiers(query) {
|
|
349
|
+
return String(query)
|
|
350
|
+
.replace(/([a-z0-9])([A-Z])/g, '$1 $2')
|
|
351
|
+
.replace(/([A-Z])([A-Z][a-z])/g, '$1 $2')
|
|
352
|
+
.toLowerCase();
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
/**
|
|
356
|
+
* A name or keyword with its separators removed, lowercased: `Side Nav`,
|
|
357
|
+
* `side-nav`, and `SideNav` all join to `sidenav`.
|
|
358
|
+
* @param {string} text
|
|
359
|
+
* @returns {string}
|
|
360
|
+
*/
|
|
361
|
+
function joined(text) {
|
|
362
|
+
return String(text)
|
|
363
|
+
.toLowerCase()
|
|
364
|
+
.replace(/[^a-z0-9]+/g, '');
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
/**
|
|
368
|
+
* The strongest hit a run of two or more adjacent query words has when it is
|
|
369
|
+
* read as one joined word, and the query words it covers. Readers type a
|
|
370
|
+
* compound name as separate words (`table header cell` is TableHeaderCell,
|
|
371
|
+
* `number field` the keyword `numberfield`), and no single word of the run
|
|
372
|
+
* matches on its own.
|
|
373
|
+
*
|
|
374
|
+
* - 100: the run joins to a component, hook, or template name, or its plural
|
|
375
|
+
* (`table header cells` is TableHeaderCell), or a hook name without its
|
|
376
|
+
* `use` prefix (`table sticky columns` is useTableStickyColumns).
|
|
377
|
+
* - 90: the run joins to a one-word keyword (`number field` is
|
|
378
|
+
* `numberfield`).
|
|
379
|
+
* - 95: the run joins to most of a name, cut short (`dropdown menu radio` is
|
|
380
|
+
* DropdownMenuRadioItem); 92: it is a name's leading words, covering at least half
|
|
381
|
+
* of it (`top nav mega` is TopNavMegaMenu); 70: it is two or more adjacent
|
|
382
|
+
* words of a name that cover at least half of it (`header cell` in
|
|
383
|
+
* TableHeaderCell), the same coverage a word prefix needs. These three
|
|
384
|
+
* are for components and hooks only.
|
|
385
|
+
*
|
|
386
|
+
* A doc's name is a route or key, so docs are left out.
|
|
387
|
+
* @param {string[]} words - The query's words, stopwords included.
|
|
388
|
+
* @param {Candidate} candidate
|
|
389
|
+
* @returns {{score: number, reason: string, covered: Set<string>, alias?: 'partial' | 'keyword', aliasWords?: number} | null}
|
|
390
|
+
* `covered` holds the run's words and every stretch of them joined. `alias`
|
|
391
|
+
* marks a hit on part of a name or on a keyword, not on the whole name.
|
|
392
|
+
*/
|
|
393
|
+
export function compoundHit(words, candidate) {
|
|
394
|
+
if (candidate.domain === 'doc' || words.length < 2) return null;
|
|
395
|
+
const names = [candidate.name, ...(candidate.aliases ?? [])]
|
|
396
|
+
.filter(Boolean)
|
|
397
|
+
.map(name => ({name, nameJoined: joined(name), nameWords: wordsOf(name)}));
|
|
398
|
+
// Part of a name counts only for a component or hook. A template's name
|
|
399
|
+
// starts with the component it shows (`ProgressBarShowcase`), so part of it
|
|
400
|
+
// names the component, not the template.
|
|
401
|
+
const partial =
|
|
402
|
+
candidate.domain === 'component' || candidate.domain === 'hook';
|
|
403
|
+
// One-word lowercase keywords: a keyword an author declares for a reader
|
|
404
|
+
// to type, joined (`numberfield`). A capitalized one names another entry (a
|
|
405
|
+
// block's `componentsUsed`), which matches by its own name, and a keyword of
|
|
406
|
+
// several words is a phrase, matched as one.
|
|
407
|
+
const keywords = (candidate.keywords ?? []).filter(k =>
|
|
408
|
+
/^[a-z0-9]+$/.test(String(k)),
|
|
409
|
+
);
|
|
410
|
+
/** @type {{score: number, reason: string, covered: Set<string>, alias?: 'partial' | 'keyword', aliasWords?: number} | null} */
|
|
411
|
+
let best = null;
|
|
412
|
+
for (const {run, word} of queryRuns(words)) {
|
|
413
|
+
let score = 0;
|
|
414
|
+
let reason = '';
|
|
415
|
+
/** @type {'partial' | 'keyword' | null} */
|
|
416
|
+
let kind = null;
|
|
417
|
+
for (const {name, nameJoined, nameWords} of names) {
|
|
418
|
+
if (
|
|
419
|
+
nameJoined === word ||
|
|
420
|
+
pluralOf(word, nameJoined) ||
|
|
421
|
+
(candidate.domain === 'hook' && nameJoined === `use${word}`)
|
|
422
|
+
) {
|
|
423
|
+
if (score < 100)
|
|
424
|
+
[score, reason, kind] = [100, `name ${name} spelled`, null];
|
|
425
|
+
} else if (!partial) {
|
|
426
|
+
continue;
|
|
427
|
+
} else if (
|
|
428
|
+
nameJoined.startsWith(word) &&
|
|
429
|
+
word.length / nameJoined.length >= 0.75
|
|
430
|
+
) {
|
|
431
|
+
// Most of the name, cut short: `dropdown menu radio` is
|
|
432
|
+
// DropdownMenuRadioItem.
|
|
433
|
+
if (score < 95)
|
|
434
|
+
[score, reason, kind] = [95, `name ${name} spelled`, 'partial'];
|
|
435
|
+
} else if (
|
|
436
|
+
word.length / nameJoined.length >= 0.5 &&
|
|
437
|
+
run.every(
|
|
438
|
+
(w, j) => nameWords[j + (nameWords[0] === 'use' ? 1 : 0)] === w,
|
|
439
|
+
)
|
|
440
|
+
) {
|
|
441
|
+
// The name's leading words: `top nav mega` is TopNavMegaMenu.
|
|
442
|
+
if (score < 92)
|
|
443
|
+
[score, reason, kind] = [
|
|
444
|
+
92,
|
|
445
|
+
`name ${name} starts "${run.join(' ')}"`,
|
|
446
|
+
'partial',
|
|
447
|
+
];
|
|
448
|
+
} else if (
|
|
449
|
+
word.length / nameJoined.length >= 0.5 &&
|
|
450
|
+
nameWords.some((_, k) => run.every((w, j) => nameWords[k + j] === w))
|
|
451
|
+
) {
|
|
452
|
+
if (score < 70)
|
|
453
|
+
[score, reason, kind] = [
|
|
454
|
+
70,
|
|
455
|
+
`name ${name} holds "${run.join(' ')}"`,
|
|
456
|
+
'partial',
|
|
457
|
+
];
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
if (score < 90 && keywords.includes(word)) {
|
|
461
|
+
[score, reason, kind] = [
|
|
462
|
+
90,
|
|
463
|
+
`keyword "${run.join(' ')}" spelled`,
|
|
464
|
+
'keyword',
|
|
465
|
+
];
|
|
466
|
+
}
|
|
467
|
+
if (score > (best?.score ?? 0)) {
|
|
468
|
+
// Each word of the run, and each identifier typed as several of its
|
|
469
|
+
// words joined (`dropdownMenu` in `dropdownMenu checkbox`).
|
|
470
|
+
const covered = new Set();
|
|
471
|
+
for (let a = 0; a < run.length; a++) {
|
|
472
|
+
for (let b = a + 1; b <= run.length; b++) {
|
|
473
|
+
covered.add(run.slice(a, b).join(''));
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
best = {
|
|
477
|
+
score,
|
|
478
|
+
reason,
|
|
479
|
+
covered,
|
|
480
|
+
...(kind ? {alias: kind, aliasWords: run.length} : {}),
|
|
481
|
+
};
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
return best;
|
|
302
485
|
}
|
|
303
486
|
|
|
487
|
+
/**
|
|
488
|
+
* The longest run of adjacent query words read as one name. Core's longest
|
|
489
|
+
* names run to six words; a longer run is a sentence, not a name, and reading
|
|
490
|
+
* every run of a long build idea costs time on every candidate.
|
|
491
|
+
*/
|
|
492
|
+
const MAX_RUN_WORDS = 6;
|
|
493
|
+
|
|
494
|
+
/**
|
|
495
|
+
* Each run of two to {@link MAX_RUN_WORDS} adjacent query words, longest
|
|
496
|
+
* first, with the run joined into one word. Computed once per query.
|
|
497
|
+
* @type {WeakMap<string[], {run: string[], word: string}[]>}
|
|
498
|
+
*/
|
|
499
|
+
const runsOf = new WeakMap();
|
|
500
|
+
|
|
501
|
+
/**
|
|
502
|
+
* @param {string[]} words
|
|
503
|
+
* @returns {{run: string[], word: string}[]}
|
|
504
|
+
*/
|
|
505
|
+
function queryRuns(words) {
|
|
506
|
+
let runs = runsOf.get(words);
|
|
507
|
+
if (runs) return runs;
|
|
508
|
+
runs = [];
|
|
509
|
+
for (let len = Math.min(words.length, MAX_RUN_WORDS); len >= 2; len--) {
|
|
510
|
+
for (let i = 0; i + len <= words.length; i++) {
|
|
511
|
+
const run = words.slice(i, i + len);
|
|
512
|
+
runs.push({run, word: run.join('')});
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
runsOf.set(words, runs);
|
|
516
|
+
return runs;
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
/**
|
|
520
|
+
* Each candidate's compound hit from its last scoreQuery, so domainPriority
|
|
521
|
+
* reads it without walking the query's runs again.
|
|
522
|
+
* @type {WeakMap<object, ReturnType<typeof compoundHit>>}
|
|
523
|
+
*/
|
|
524
|
+
const compoundOf = new WeakMap();
|
|
525
|
+
|
|
304
526
|
/**
|
|
305
527
|
* The fewest letters both words need before an edit distance counts as a
|
|
306
528
|
* typo, by distance. Below them, one edit usually makes a different word.
|
|
@@ -513,19 +735,20 @@ const STRONG_TOKEN_SCORE = 70;
|
|
|
513
735
|
* typography/font-setup, `side panel` is "Side panels");
|
|
514
736
|
* - 1: a word of the query is the topic's name (`illustration` in a longer
|
|
515
737
|
* question is the illustrations guide);
|
|
738
|
+
* - 1: a query of two or more words is one of the topic's own declared
|
|
739
|
+
* keywords, whatever the plural (`code review` on a guide that declares it);
|
|
516
740
|
* - 1: the query holds one of the doc's titles whole (`resizable side panels`
|
|
517
741
|
* names "Side panels"; `light dark mode button` names "Light/Dark Mode");
|
|
518
742
|
* - 1: the doc matches every word of the query and one of them is a word of
|
|
519
743
|
* its title (`switch to a dark theme` and "Use a theme").
|
|
520
744
|
* A section answers to its topic's name.
|
|
521
745
|
*
|
|
522
|
-
* A doc that matched only by
|
|
746
|
+
* A doc that matched only by a heading holding the query, by one word, or by
|
|
523
747
|
* words spread through its text has no priority. Docs are split into many
|
|
524
|
-
* small topics,
|
|
525
|
-
*
|
|
526
|
-
*
|
|
527
|
-
*
|
|
528
|
-
* above the component. Broad reference pages match every word of many queries
|
|
748
|
+
* small topics, each with its own headings, so a common phrase such as
|
|
749
|
+
* `font size` hits a heading exactly (170) while the component the reader is
|
|
750
|
+
* after matches one word by keyword (`Text`, 98). Ranked on text alone, every
|
|
751
|
+
* split adds another doc above the component. Broad reference pages match every word of many queries
|
|
529
752
|
* in their text the same way. The score stays the text-match strength the
|
|
530
753
|
* result reports, so callers that gate on it (`build`) see the same numbers.
|
|
531
754
|
*
|
|
@@ -536,7 +759,13 @@ const STRONG_TOKEN_SCORE = 70;
|
|
|
536
759
|
* candidate's scoreQuery result.
|
|
537
760
|
* @returns {0 | 1 | 2}
|
|
538
761
|
*/
|
|
539
|
-
export function domainPriority(
|
|
762
|
+
export function domainPriority(
|
|
763
|
+
term,
|
|
764
|
+
tokens,
|
|
765
|
+
candidate,
|
|
766
|
+
hit,
|
|
767
|
+
queryWords = phraseWords(term),
|
|
768
|
+
) {
|
|
540
769
|
const words = [term, ...tokens];
|
|
541
770
|
if (candidate.domain === 'doc') {
|
|
542
771
|
const topic = String(candidate._topic ?? candidate.name).toLowerCase();
|
|
@@ -551,6 +780,20 @@ export function domainPriority(term, tokens, candidate, hit) {
|
|
|
551
780
|
if (named.some(n => samePhrase(term, n))) {
|
|
552
781
|
return 2;
|
|
553
782
|
}
|
|
783
|
+
// A query of two or more words that is one of the doc's own declared
|
|
784
|
+
// keywords, read as words whatever the plural, is the author naming the
|
|
785
|
+
// doc for that phrase: `code review` on a guide that declares it. Only
|
|
786
|
+
// what the author declared counts: the code terms and table cells a
|
|
787
|
+
// doc's other keywords add (`missing_field`) name what it mentions, not
|
|
788
|
+
// what it is for. One word is left out too, and a section declares
|
|
789
|
+
// nothing.
|
|
790
|
+
if (
|
|
791
|
+
phraseWords(term).length >= 2 &&
|
|
792
|
+
candidate._section == null &&
|
|
793
|
+
(candidate._declared ?? []).some(k => samePhrase(term, String(k)))
|
|
794
|
+
) {
|
|
795
|
+
return 1;
|
|
796
|
+
}
|
|
554
797
|
if (
|
|
555
798
|
words.some(
|
|
556
799
|
w =>
|
|
@@ -581,6 +824,12 @@ export function domainPriority(term, tokens, candidate, hit) {
|
|
|
581
824
|
return 0;
|
|
582
825
|
}
|
|
583
826
|
if (hit.score >= FULL_COVERAGE_SCORE) return 1;
|
|
827
|
+
const compound = compoundOf.has(candidate)
|
|
828
|
+
? compoundOf.get(candidate)
|
|
829
|
+
: compoundHit(queryWords, candidate);
|
|
830
|
+
if ((compound?.score ?? 0) >= STRONG_TOKEN_SCORE) {
|
|
831
|
+
return 1;
|
|
832
|
+
}
|
|
584
833
|
const fuzzy = tokens.length <= 1;
|
|
585
834
|
return words.some(
|
|
586
835
|
w =>
|
|
@@ -696,14 +945,24 @@ export function titleInQuery(term, titles) {
|
|
|
696
945
|
* @param {string} term - Lowercased full query.
|
|
697
946
|
* @param {string[]} tokens - Content tokens from tokenizeQuery(term).
|
|
698
947
|
* @param {Candidate} candidate
|
|
699
|
-
* @
|
|
948
|
+
* @param {string[]} [words] - The query's words for compound names (see
|
|
949
|
+
* compoundHit); empty when the query names an entry outright.
|
|
950
|
+
* @param {{plain?: boolean}} [opts] - `plain`: score without matches on part
|
|
951
|
+
* of a name or a joined keyword.
|
|
952
|
+
* @returns {{score: number, reason: string, matched: number, total: number, alias?: 'partial' | 'keyword', aliasWords?: number} | null}
|
|
700
953
|
* `matched`/`total` are the query concepts this candidate answered, out of
|
|
701
954
|
* the concepts the query had. Callers that must distinguish "matched one word
|
|
702
955
|
* of three" from "matched all three" — `build`, which gates its pages group
|
|
703
956
|
* on coverage — cannot recover that from the score, because a single strong
|
|
704
957
|
* hit and a broad weak one land on the same number.
|
|
705
958
|
*/
|
|
706
|
-
export function scoreQuery(
|
|
959
|
+
export function scoreQuery(
|
|
960
|
+
term,
|
|
961
|
+
tokens,
|
|
962
|
+
candidate,
|
|
963
|
+
words = phraseWords(term),
|
|
964
|
+
{plain = false} = {},
|
|
965
|
+
) {
|
|
707
966
|
const total = Math.max(tokens.length, 1);
|
|
708
967
|
// A whole-phrase hit answered the whole query by definition.
|
|
709
968
|
const asFull = (/** @type {{score: number, reason: string}} */ hit) => ({
|
|
@@ -712,14 +971,24 @@ export function scoreQuery(term, tokens, candidate) {
|
|
|
712
971
|
total,
|
|
713
972
|
});
|
|
714
973
|
// Typo tolerance is for one-word lookups. In a multi-word query a near miss
|
|
715
|
-
// is usually a different word, not a typo.
|
|
716
|
-
|
|
717
|
-
const
|
|
974
|
+
// is usually a different word, not a typo. One typed identifier is one
|
|
975
|
+
// word, whatever words it spells.
|
|
976
|
+
const fuzzy = tokens.length <= 1 || !/\s/.test(term);
|
|
977
|
+
const full = scoreCandidate(term, candidate, {
|
|
978
|
+
fuzzy,
|
|
979
|
+
joins: !plain && words.length > 0,
|
|
980
|
+
});
|
|
718
981
|
// A query of several words keeps its phrase tiers below even when stopwords
|
|
719
982
|
// leave one content word: "make an integration" is still the phrase an
|
|
720
983
|
// author declares as a keyword, and "build an integration" still names a
|
|
721
984
|
// title outright, though each tokenizes to `integration` alone.
|
|
722
|
-
const phrase = phraseWords(term).length >= 2;
|
|
985
|
+
const phrase = phraseWords(term).length >= 2 || words.length >= 2;
|
|
986
|
+
let compound = compoundHit(words, candidate);
|
|
987
|
+
if (plain) {
|
|
988
|
+
if (compound?.alias) compound = null;
|
|
989
|
+
} else {
|
|
990
|
+
compoundOf.set(candidate, compound);
|
|
991
|
+
}
|
|
723
992
|
|
|
724
993
|
/** 0–1 content tokens: whole-phrase fuzzy matching (typo tolerance for
|
|
725
994
|
* single words), but if stopwords left exactly one DIFFERENT token (e.g.
|
|
@@ -744,7 +1013,11 @@ export function scoreQuery(term, tokens, candidate) {
|
|
|
744
1013
|
// of Table-related templates each match "table" and "contents" separately
|
|
745
1014
|
// and accumulate a higher raw score (#5239).
|
|
746
1015
|
if (full && full.score >= 90) {
|
|
747
|
-
return asFull({
|
|
1016
|
+
return asFull({
|
|
1017
|
+
score: full.score + 100,
|
|
1018
|
+
reason: full.reason,
|
|
1019
|
+
...(full.alias ? {alias: full.alias, aliasWords: words.length} : {}),
|
|
1020
|
+
});
|
|
748
1021
|
}
|
|
749
1022
|
|
|
750
1023
|
// The whole query standing as a phrase in a doc's title or one of its
|
|
@@ -770,8 +1043,25 @@ export function scoreQuery(term, tokens, candidate) {
|
|
|
770
1043
|
let tokenSum = 0;
|
|
771
1044
|
/** @type {string[]} */
|
|
772
1045
|
const hitTerms = [];
|
|
1046
|
+
// Adjacent words that join into a name or keyword answer each word they
|
|
1047
|
+
// join, as strongly as the joined word matches (see compoundHit).
|
|
1048
|
+
// Whether a counted word matched only through part of a name or a keyword
|
|
1049
|
+
// read joined, not through the entry's own name or a word of it.
|
|
1050
|
+
/** @type {'partial' | 'keyword' | false} */
|
|
1051
|
+
let alias = false;
|
|
1052
|
+
let aliasWords = 0;
|
|
773
1053
|
for (const tok of tokens) {
|
|
774
|
-
|
|
1054
|
+
let h = bestForToken(tok, candidate, {fuzzy});
|
|
1055
|
+
if (
|
|
1056
|
+
compound?.covered.has(joined(tok)) &&
|
|
1057
|
+
compound.score > (h?.score ?? 0)
|
|
1058
|
+
) {
|
|
1059
|
+
h = compound;
|
|
1060
|
+
if (compound.alias && compound.score >= MIN_TOKEN_SCORE) {
|
|
1061
|
+
alias = alias === 'partial' ? alias : compound.alias;
|
|
1062
|
+
aliasWords = compound.aliasWords ?? 0;
|
|
1063
|
+
}
|
|
1064
|
+
}
|
|
775
1065
|
if (h && h.score >= MIN_TOKEN_SCORE) {
|
|
776
1066
|
if (h.score > strongest) strongest = h.score;
|
|
777
1067
|
matched++;
|
|
@@ -821,6 +1111,7 @@ export function scoreQuery(term, tokens, candidate) {
|
|
|
821
1111
|
reason,
|
|
822
1112
|
matched,
|
|
823
1113
|
total,
|
|
1114
|
+
...(alias ? {alias, aliasWords} : {}),
|
|
824
1115
|
};
|
|
825
1116
|
}
|
|
826
1117
|
|
|
@@ -846,7 +1137,13 @@ export function scoreQuery(term, tokens, candidate) {
|
|
|
846
1137
|
strongest + Math.min(matched - 1, 3) * 12 + coverage * 15,
|
|
847
1138
|
);
|
|
848
1139
|
if (full && full.score >= tokenScore) return asFull(full);
|
|
849
|
-
return {
|
|
1140
|
+
return {
|
|
1141
|
+
score: tokenScore,
|
|
1142
|
+
reason,
|
|
1143
|
+
matched,
|
|
1144
|
+
total,
|
|
1145
|
+
...(alias ? {alias, aliasWords} : {}),
|
|
1146
|
+
};
|
|
850
1147
|
}
|
|
851
1148
|
|
|
852
1149
|
/**
|
|
@@ -865,8 +1162,9 @@ export function scoreQuery(term, tokens, candidate) {
|
|
|
865
1162
|
* @param {string} [candidate.description]
|
|
866
1163
|
* @param {string[]} [candidate.prose] - Extra free-text blobs (doc section text, best practices).
|
|
867
1164
|
* @param {string[]} [candidate.guidance] - Usage guidance (features, best practices) — scored a tier below description.
|
|
868
|
-
* @param {{fuzzy?: boolean}} [opts] - `fuzzy`: allow edit-distance (typo) matches. Default true; multi-word queries pass false.
|
|
869
|
-
* @returns {{score: number, reason: string} | null}
|
|
1165
|
+
* @param {{fuzzy?: boolean, joins?: boolean}} [opts] - `fuzzy`: allow edit-distance (typo) matches. Default true; multi-word queries pass false. `joins`: read a spaced query joined into a name or keyword (default true); off when the query names an entry outright.
|
|
1166
|
+
* @returns {{score: number, reason: string, alias?: 'partial' | 'keyword'} | null}
|
|
1167
|
+
* `alias` marks a hit that read the query's words joined.
|
|
870
1168
|
*/
|
|
871
1169
|
export function scoreCandidate(
|
|
872
1170
|
term,
|
|
@@ -880,18 +1178,23 @@ export function scoreCandidate(
|
|
|
880
1178
|
prose = [],
|
|
881
1179
|
guidance = [],
|
|
882
1180
|
},
|
|
883
|
-
{fuzzy = true} = {},
|
|
1181
|
+
{fuzzy = true, joins = true} = {},
|
|
884
1182
|
) {
|
|
885
1183
|
let best = 0;
|
|
886
1184
|
let reason = '';
|
|
1185
|
+
/** @type {'partial' | 'keyword' | false} */
|
|
1186
|
+
let alias = false;
|
|
887
1187
|
/**
|
|
888
1188
|
* @param {number} score
|
|
889
1189
|
* @param {string} why
|
|
1190
|
+
* @param {'partial' | 'keyword' | false} [byAlias] - the hit reads the
|
|
1191
|
+
* query's words joined, into part of a name or into a keyword
|
|
890
1192
|
*/
|
|
891
|
-
const consider = (score, why) => {
|
|
1193
|
+
const consider = (score, why, byAlias = false) => {
|
|
892
1194
|
if (score > best) {
|
|
893
1195
|
best = score;
|
|
894
1196
|
reason = why;
|
|
1197
|
+
alias = byAlias;
|
|
895
1198
|
}
|
|
896
1199
|
};
|
|
897
1200
|
|
|
@@ -915,6 +1218,16 @@ export function scoreCandidate(
|
|
|
915
1218
|
nameLower === term.replace(/\s+/g, '');
|
|
916
1219
|
if (nameLower === term || leafLower === term || spelled) {
|
|
917
1220
|
consider(100, 'exact name');
|
|
1221
|
+
} else if (
|
|
1222
|
+
joins &&
|
|
1223
|
+
(domain === 'component' || domain === 'hook') &&
|
|
1224
|
+
/\s/.test(term) &&
|
|
1225
|
+
nameLower.startsWith(term.replace(/\s+/g, '')) &&
|
|
1226
|
+
term.replace(/\s+/g, '').length / nameLower.length >= 0.75
|
|
1227
|
+
) {
|
|
1228
|
+
// Most of the name typed as words, cut short: `complex select` is
|
|
1229
|
+
// ComplexSelector, ahead of a one-word keyword elsewhere.
|
|
1230
|
+
consider(95, `name "${candidateName}" spelled`, 'partial');
|
|
918
1231
|
} else if (pluralOf(nameLower, term) || pluralOf(term, nameLower)) {
|
|
919
1232
|
// One point under the exact spelling, so the doc named `tokens` still
|
|
920
1233
|
// outranks the Token component for `tokens`.
|
|
@@ -938,12 +1251,27 @@ export function scoreCandidate(
|
|
|
938
1251
|
}
|
|
939
1252
|
|
|
940
1253
|
// ── Keyword signals ─────────────────────────────────────────────
|
|
1254
|
+
const termJoined = joined(term);
|
|
941
1255
|
for (const kw of keywords) {
|
|
942
1256
|
const kwLower = String(kw).toLowerCase();
|
|
1257
|
+
// A one-word keyword typed as separate words is the keyword: `number
|
|
1258
|
+
// field` is `numberfield`. Only a
|
|
1259
|
+
// lowercase keyword, one an author declares for a reader to type: a
|
|
1260
|
+
// capitalized one names another entry (a block's `componentsUsed`). A
|
|
1261
|
+
// doc's keywords include code terms, matched as written.
|
|
943
1262
|
if (kwLower === term) {
|
|
944
1263
|
consider(90, `keyword "${kw}"`);
|
|
945
1264
|
continue;
|
|
946
1265
|
}
|
|
1266
|
+
if (
|
|
1267
|
+
joins &&
|
|
1268
|
+
domain !== 'doc' &&
|
|
1269
|
+
/\s/.test(term) &&
|
|
1270
|
+
String(kw) === termJoined
|
|
1271
|
+
) {
|
|
1272
|
+
consider(90, `keyword "${kw}"`, 'keyword');
|
|
1273
|
+
continue;
|
|
1274
|
+
}
|
|
947
1275
|
if (sameWord(term, kwLower)) {
|
|
948
1276
|
consider(88, `keyword "${kw}"`);
|
|
949
1277
|
continue;
|
|
@@ -975,9 +1303,12 @@ export function scoreCandidate(
|
|
|
975
1303
|
// Match the term's stem as a whole word, tolerating plural/gerund suffixes
|
|
976
1304
|
// so "chart" matches "charts" and "filter" matches "filtering".
|
|
977
1305
|
if (term.length >= 3) {
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
const
|
|
1306
|
+
// Any form of the term, with any common suffix: `spacing` finds
|
|
1307
|
+
// "space" and "spaces", `tables` finds "table".
|
|
1308
|
+
const roots = [...new Set([stem(term), ...wordForms(term)])]
|
|
1309
|
+
.filter(f => f.length >= 3)
|
|
1310
|
+
.map(f => f.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'));
|
|
1311
|
+
const re = new RegExp(`\\b(?:${roots.join('|')})(s|es|ing|ed|ies)?\\b`);
|
|
981
1312
|
if (description && re.test(description.toLowerCase())) {
|
|
982
1313
|
consider(50, `description mentions "${term}"`);
|
|
983
1314
|
} else {
|
|
@@ -1003,7 +1334,7 @@ export function scoreCandidate(
|
|
|
1003
1334
|
}
|
|
1004
1335
|
}
|
|
1005
1336
|
|
|
1006
|
-
return best > 0 ? {score: best, reason} : null;
|
|
1337
|
+
return best > 0 ? {score: best, reason, ...(alias ? {alias} : {})} : null;
|
|
1007
1338
|
}
|
|
1008
1339
|
|
|
1009
1340
|
/**
|
|
@@ -1508,6 +1839,10 @@ async function gatherDocs(cwd) {
|
|
|
1508
1839
|
...defined,
|
|
1509
1840
|
...codeTerms({content}),
|
|
1510
1841
|
],
|
|
1842
|
+
_declared: [
|
|
1843
|
+
...(Array.isArray(selfDoc?.keywords) ? selfDoc.keywords : []),
|
|
1844
|
+
...(Array.isArray(node.keywords) ? node.keywords : []),
|
|
1845
|
+
],
|
|
1511
1846
|
description: node.summary || '',
|
|
1512
1847
|
prose: sectionProse({title: node.title, content}),
|
|
1513
1848
|
titles: [node.title],
|
|
@@ -1644,6 +1979,7 @@ function topicCandidates(
|
|
|
1644
1979
|
...(doc?.title || title ? [doc?.title || title] : []),
|
|
1645
1980
|
...(Array.isArray(doc?.keywords) ? doc.keywords : []),
|
|
1646
1981
|
],
|
|
1982
|
+
_declared: Array.isArray(doc?.keywords) ? doc.keywords : [],
|
|
1647
1983
|
description: doc?.description || summary,
|
|
1648
1984
|
prose: split
|
|
1649
1985
|
? sections.map(section => section.title).filter(Boolean)
|
|
@@ -1903,8 +2239,6 @@ async function searchOnce(query, options) {
|
|
|
1903
2239
|
}
|
|
1904
2240
|
|
|
1905
2241
|
const term = String(query).trim().toLowerCase();
|
|
1906
|
-
const tokens = tokenizeQuery(term);
|
|
1907
|
-
|
|
1908
2242
|
// `astryx docs` reads docs without @astryxdesign/core, and `astryx theme
|
|
1909
2243
|
// list` reads themes without it (bundled themes need no project), so a
|
|
1910
2244
|
// search of either must too. Every other domain reads core: asked for by
|
|
@@ -1936,14 +2270,100 @@ async function searchOnce(query, options) {
|
|
|
1936
2270
|
|
|
1937
2271
|
const all = [...components, ...hooks, ...docTopics, ...templates, ...themes];
|
|
1938
2272
|
|
|
2273
|
+
// A query that is one identifier counts as the words it spells
|
|
2274
|
+
// (`SidebarToggle`), and still matches whole as typed. In a query of several
|
|
2275
|
+
// words, each identifier stays one term (`ChatComposer ChatLayout` names two
|
|
2276
|
+
// components), and its words still join into names (see compoundHit). Both
|
|
2277
|
+
// only help a query that names no entry outright: when the query is an
|
|
2278
|
+
// entry's name, typed whole or as its words, that entry answers it, and
|
|
2279
|
+
// neither reading may add near siblings beside it.
|
|
2280
|
+
const spelled = spellIdentifiers(String(query).trim());
|
|
2281
|
+
const exact = all.some(candidate =>
|
|
2282
|
+
[candidate.name, ...(candidate.aliases ?? [])].some(name => {
|
|
2283
|
+
const lower = String(name).toLowerCase();
|
|
2284
|
+
return (
|
|
2285
|
+
lower === term ||
|
|
2286
|
+
(candidate.domain !== 'doc' &&
|
|
2287
|
+
!/[\s_-]/.test(lower) &&
|
|
2288
|
+
lower === term.replace(/\s+/g, ''))
|
|
2289
|
+
);
|
|
2290
|
+
}),
|
|
2291
|
+
);
|
|
2292
|
+
// One identifier is read as its words only when, read whole, it matches
|
|
2293
|
+
// nothing: a prop or hook name a doc already mentions keeps the
|
|
2294
|
+
// entries that mention it.
|
|
2295
|
+
const split =
|
|
2296
|
+
!exact &&
|
|
2297
|
+
!/\s/.test(term) &&
|
|
2298
|
+
spelled !== term &&
|
|
2299
|
+
!all.some(candidate => scoreCandidate(term, candidate));
|
|
2300
|
+
const tokens = tokenizeQuery(split ? spelled : term);
|
|
2301
|
+
/** @type {string[]} */
|
|
2302
|
+
const words = exact
|
|
2303
|
+
? []
|
|
2304
|
+
: phraseWords(split || /\s/.test(term) ? spelled : term);
|
|
2305
|
+
// The entries the query names: a component, hook, or template whose whole
|
|
2306
|
+
// name is adjacent query words joined (`icon button in a card header` names
|
|
2307
|
+
// IconButton), or one identifier typed as such. A name inside a longer named
|
|
2308
|
+
// run does not count (`icon` there is part of IconButton).
|
|
2309
|
+
const queryWords = phraseWords(spelled);
|
|
2310
|
+
const typedIdentifiers = new Set(
|
|
2311
|
+
(String(query).match(/[A-Za-z0-9]+/g) ?? [])
|
|
2312
|
+
.filter(w => /[A-Z]/.test(w))
|
|
2313
|
+
.map(w => w.toLowerCase()),
|
|
2314
|
+
);
|
|
2315
|
+
/** @type {Map<string, [number, number]>} each run joined, longest first */
|
|
2316
|
+
const spans = new Map();
|
|
2317
|
+
for (let len = Math.min(queryWords.length, MAX_RUN_WORDS); len >= 1; len--) {
|
|
2318
|
+
for (let a = 0; a + len <= queryWords.length; a++) {
|
|
2319
|
+
// One plain word names too much (`list`, `field`); a named entry is a
|
|
2320
|
+
// run of joined words, or an identifier typed as one.
|
|
2321
|
+
if (len === 1 && !typedIdentifiers.has(queryWords[a])) continue;
|
|
2322
|
+
const run = queryWords.slice(a, a + len).join('');
|
|
2323
|
+
if (!spans.has(run)) spans.set(run, [a, a + len]);
|
|
2324
|
+
}
|
|
2325
|
+
}
|
|
2326
|
+
/**
|
|
2327
|
+
* Where a query word is the candidate's whole name, or null: such an entry
|
|
2328
|
+
* keeps the rank its name earns, whatever else it matched.
|
|
2329
|
+
* @param {Candidate} candidate
|
|
2330
|
+
* @returns {[number, number] | null}
|
|
2331
|
+
*/
|
|
2332
|
+
const wordNamed = candidate => {
|
|
2333
|
+
if (candidate.domain === 'doc') return null;
|
|
2334
|
+
for (const name of [candidate.name, ...(candidate.aliases ?? [])]) {
|
|
2335
|
+
const n = joined(name);
|
|
2336
|
+
const at = queryWords.findIndex(w => w === n || w === `${n}s`);
|
|
2337
|
+
if (at >= 0) return [at, at + 1];
|
|
2338
|
+
}
|
|
2339
|
+
return null;
|
|
2340
|
+
};
|
|
2341
|
+
/** @param {Candidate} candidate @returns {[number, number] | null} */
|
|
2342
|
+
const namedSpan = candidate => {
|
|
2343
|
+
if (candidate.domain === 'doc') return null;
|
|
2344
|
+
/** @type {[number, number] | null} */
|
|
2345
|
+
let best = null;
|
|
2346
|
+
for (const name of [candidate.name, ...(candidate.aliases ?? [])]) {
|
|
2347
|
+
const n = joined(name);
|
|
2348
|
+
const span =
|
|
2349
|
+
spans.get(n) ??
|
|
2350
|
+
spans.get(`${n}s`) ??
|
|
2351
|
+
(/(?:s|x|z|ch|sh)$/.test(n) ? spans.get(`${n}es`) : undefined);
|
|
2352
|
+
if (span && (!best || span[1] - span[0] > best[1] - best[0])) {
|
|
2353
|
+
best = span;
|
|
2354
|
+
}
|
|
2355
|
+
}
|
|
2356
|
+
return best;
|
|
2357
|
+
};
|
|
2358
|
+
|
|
1939
2359
|
// Score every candidate on its own merits. The consumer groups results by
|
|
1940
2360
|
// role (page / block / component) and takes the top of each, so there's no
|
|
1941
2361
|
// cross-role competition to engineer — a target page only needs to be the
|
|
1942
2362
|
// strongest PAGE, not outrank every component.
|
|
1943
|
-
/** @type {{result: any, priority: 0 | 1 | 2}[]} */
|
|
2363
|
+
/** @type {{result: any, priority: 0 | 1 | 2, key: number, alias: 'partial' | 'keyword' | false, aliasWords: number, candidate: Candidate, span: [number, number] | null, word: [number, number] | null}[]} */
|
|
1944
2364
|
const ranked = [];
|
|
1945
2365
|
for (const candidate of all) {
|
|
1946
|
-
const hit = scoreQuery(term, tokens, candidate);
|
|
2366
|
+
const hit = scoreQuery(term, tokens, candidate, words);
|
|
1947
2367
|
if (hit)
|
|
1948
2368
|
ranked.push({
|
|
1949
2369
|
result: toResult(
|
|
@@ -1953,9 +2373,54 @@ async function searchOnce(query, options) {
|
|
|
1953
2373
|
hit.matched,
|
|
1954
2374
|
hit.total,
|
|
1955
2375
|
),
|
|
1956
|
-
priority: domainPriority(term, tokens, candidate, hit),
|
|
2376
|
+
priority: domainPriority(term, tokens, candidate, hit, words),
|
|
2377
|
+
key: hit.score,
|
|
2378
|
+
alias: hit.alias ?? false,
|
|
2379
|
+
aliasWords: hit.aliasWords ?? 0,
|
|
2380
|
+
candidate,
|
|
2381
|
+
span: namedSpan(candidate),
|
|
2382
|
+
word: wordNamed(candidate),
|
|
1957
2383
|
});
|
|
1958
2384
|
}
|
|
2385
|
+
// A match on a keyword read joined never outranks an entry the query names,
|
|
2386
|
+
// and neither does a match on part of another name unless it spans more
|
|
2387
|
+
// query words than any named run: `table header with sticky columns` keeps
|
|
2388
|
+
// TableHeader above useTableStickyColumns, which only holds the words
|
|
2389
|
+
// `sticky columns`. Only the order changes; each result keeps the score its
|
|
2390
|
+
// text earned.
|
|
2391
|
+
/** @param {[number, number]} inner @param {[number, number]} outer */
|
|
2392
|
+
const inside = (inner, outer) =>
|
|
2393
|
+
outer[0] <= inner[0] &&
|
|
2394
|
+
outer[1] >= inner[1] &&
|
|
2395
|
+
outer[1] - outer[0] > inner[1] - inner[0];
|
|
2396
|
+
const named = ranked.filter(r => {
|
|
2397
|
+
const span = r.span;
|
|
2398
|
+
return (
|
|
2399
|
+
span != null &&
|
|
2400
|
+
!ranked.some(o => o !== r && o.span != null && inside(span, o.span))
|
|
2401
|
+
);
|
|
2402
|
+
});
|
|
2403
|
+
/** @param {{key: number}[]} rows */
|
|
2404
|
+
const floorOf = rows =>
|
|
2405
|
+
rows.length ? Math.min(...rows.map(r => r.key)) : Infinity;
|
|
2406
|
+
const namedFloor = floorOf(named);
|
|
2407
|
+
const longestNamed = Math.max(
|
|
2408
|
+
0,
|
|
2409
|
+
...named.map(r => (r.span ? r.span[1] - r.span[0] : 0)),
|
|
2410
|
+
);
|
|
2411
|
+
for (const r of ranked) {
|
|
2412
|
+
if (named.includes(r)) continue;
|
|
2413
|
+
if (!r.alias || r.word) continue;
|
|
2414
|
+
// A match on part of a longer name that spans more words than any named
|
|
2415
|
+
// run reads more of the query than the named entry does (`dropdown menu
|
|
2416
|
+
// radio` and DropdownMenuRadioItem, against DropdownMenu), so it is not
|
|
2417
|
+
// held back. A joined keyword always is.
|
|
2418
|
+
if (r.alias === 'partial' && r.aliasWords > longestNamed) continue;
|
|
2419
|
+
// It keeps what it earns without those matches.
|
|
2420
|
+
const own =
|
|
2421
|
+
scoreQuery(term, tokens, r.candidate, words, {plain: true})?.score ?? 0;
|
|
2422
|
+
r.key = Math.max(own, Math.min(r.key, namedFloor - 0.5));
|
|
2423
|
+
}
|
|
1959
2424
|
|
|
1960
2425
|
// Docs and everything else are each sorted by score desc, then domain
|
|
1961
2426
|
// (stable order), then name. The two are merged: at each step the stronger
|
|
@@ -1964,11 +2429,11 @@ async function searchOnce(query, options) {
|
|
|
1964
2429
|
/** @type {Record<string, number>} */
|
|
1965
2430
|
const domainOrder = {component: 0, hook: 1, doc: 2, template: 3, theme: 4};
|
|
1966
2431
|
/**
|
|
1967
|
-
* @param {{result: any}} x
|
|
1968
|
-
* @param {{result: any}} y
|
|
2432
|
+
* @param {{result: any, key: number}} x
|
|
2433
|
+
* @param {{result: any, key: number}} y
|
|
1969
2434
|
*/
|
|
1970
|
-
const byScore = ({result: a}, {result: b}) =>
|
|
1971
|
-
|
|
2435
|
+
const byScore = ({result: a, key: ka}, {result: b, key: kb}) =>
|
|
2436
|
+
kb - ka ||
|
|
1972
2437
|
(domainOrder[a.domain] ?? 9) - (domainOrder[b.domain] ?? 9) ||
|
|
1973
2438
|
a.name.localeCompare(b.name);
|
|
1974
2439
|
const others = ranked.filter(r => r.result.domain !== 'doc').sort(byScore);
|
|
@@ -2021,5 +2486,5 @@ async function searchOnce(query, options) {
|
|
|
2021
2486
|
components.map(c => ({name: c.name, keywords: c.keywords ?? []})),
|
|
2022
2487
|
);
|
|
2023
2488
|
}
|
|
2024
|
-
return response;
|
|
2489
|
+
return linkSearchResponse(response, cwd);
|
|
2025
2490
|
}
|