@astryxdesign/cli 0.7.2-canary.ba6a6e2 → 0.7.2-canary.bd72a5f
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 +72 -1
- package/api/component/_adapter.mjs +209 -7
- package/api/component/component.mjs +82 -15
- package/api/component/component.test.mjs +80 -0
- package/api/component/doc-links.test.mjs +386 -0
- package/api/component/integration-export-name.test.mjs +644 -0
- package/api/component/list/list.mjs +42 -4
- 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 +219 -52
- 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.component-names.test.mjs +66 -0
- package/api/integration/add-contribution.mjs +8 -4
- 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 +357 -114
- package/api/integration/pack-check.test.mjs +726 -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 +81 -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 +611 -54
- package/api/search/search.test.mjs +175 -0
- package/api/swizzle/copy/copy.mjs +28 -14
- package/api/theme/build/build.family.test.mjs +64 -0
- package/api/theme/build/build.mjs +180 -24
- 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 +11 -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 +26 -18
- package/assets/docs/tree/codemods.doc.mjs +4 -4
- package/assets/docs/tree/component-family.doc.mjs +8 -6
- package/assets/docs/tree/component-imports.doc.mjs +10 -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 +15 -6
- 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 +16 -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 +7 -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/docs/working-with-ai.doc.mjs +43 -4
- 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 +30 -27
- package/authoring/doctypes/component/type.ts +21 -8
- 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 +224 -6
- package/clients/cli/commands/build-theme.registry.test.mjs +5 -2
- 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 +190 -10
- package/foundation/discovery/component-discovery.export-names.test.mjs +760 -0
- package/foundation/discovery/component-discovery.mjs +864 -56
- package/foundation/discovery/component-discovery.test.mjs +96 -0
- package/foundation/discovery/component-replacement.mjs +18 -0
- package/foundation/discovery/component-replacement.test.mjs +40 -0
- 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/module-exports.d.mts +27 -0
- package/foundation/discovery/module-exports.mjs +356 -31
- package/foundation/discovery/module-exports.test.mjs +172 -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 +30 -0
- package/foundation/doc-compiler/inputs.mjs +23 -0
- package/foundation/doc-compiler/inputs.test.mjs +0 -1
- 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 +56 -3
- 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/foundation/xle/registry.mjs +4 -0
- package/foundation/xle/registry.test.mjs +28 -0
- 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
|
|
@@ -81,11 +82,20 @@
|
|
|
81
82
|
|
|
82
83
|
import {withListingCache} from '../../foundation/fs/listing-cache.mjs';
|
|
83
84
|
import {readDocView} from '../../foundation/doc-compiler/read.mjs';
|
|
84
|
-
import {
|
|
85
|
+
import {
|
|
86
|
+
discoverExternalPackages,
|
|
87
|
+
findCoreDir,
|
|
88
|
+
} from '../../foundation/fs/paths.mjs';
|
|
85
89
|
import {
|
|
86
90
|
discoverComponents,
|
|
87
91
|
discoverValidIntegrationComponents,
|
|
92
|
+
docStem,
|
|
93
|
+
familyMember,
|
|
88
94
|
findComponentReadme,
|
|
95
|
+
forEachIntegrationDoc,
|
|
96
|
+
integrationMemberEntry,
|
|
97
|
+
integrationRecordHold,
|
|
98
|
+
isIntegrationMember,
|
|
89
99
|
resolveImportPath,
|
|
90
100
|
resolveIntegrationImportPath,
|
|
91
101
|
CORE_PACKAGE,
|
|
@@ -97,6 +107,7 @@ import {
|
|
|
97
107
|
import {
|
|
98
108
|
loadComponentReplacements,
|
|
99
109
|
loadIntegrationsSafely,
|
|
110
|
+
resolveLegacyExternalDoc,
|
|
100
111
|
} from '../component/_adapter.mjs';
|
|
101
112
|
import {levenshteinDistance} from '../../foundation/text/string-utils.mjs';
|
|
102
113
|
import {discoverTemplates, extractComponents} from '../template/template.mjs';
|
|
@@ -118,6 +129,7 @@ import {
|
|
|
118
129
|
import {AstryxError} from '../error.mjs';
|
|
119
130
|
import {ERROR_CODES} from '../../foundation/response/error-codes.mjs';
|
|
120
131
|
import {setResultCoverage} from './coverage.mjs';
|
|
132
|
+
import {linkSearchResponse} from '../component/_adapter.mjs';
|
|
121
133
|
|
|
122
134
|
/**
|
|
123
135
|
* A search candidate gathered from one content domain. Extra underscore-
|
|
@@ -128,6 +140,9 @@ import {setResultCoverage} from './coverage.mjs';
|
|
|
128
140
|
* @property {string[]} [aliases] - Other names the candidate answers to, scored
|
|
129
141
|
* with the same name signals: a theme's display name.
|
|
130
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.
|
|
131
146
|
* @property {string[]} [weakKeywords]
|
|
132
147
|
* @property {string} [description]
|
|
133
148
|
* @property {string[]} [prose]
|
|
@@ -149,6 +164,9 @@ import {setResultCoverage} from './coverage.mjs';
|
|
|
149
164
|
* @property {'page'|'block'} [_kind]
|
|
150
165
|
* @property {string} [_resultName]
|
|
151
166
|
* @property {string} [_commandName]
|
|
167
|
+
* @property {'file'|'doc'} [_hold] - How an integration component holds its
|
|
168
|
+
* name, for the owner rule.
|
|
169
|
+
* @property {string} [_docPath] - An integration component's doc.
|
|
152
170
|
*/
|
|
153
171
|
|
|
154
172
|
/**
|
|
@@ -242,9 +260,34 @@ function wordForms(w) {
|
|
|
242
260
|
if (w.length > 3 && w.endsWith('s')) forms.add(w.slice(0, -1));
|
|
243
261
|
if (w.length > 4 && w.endsWith('es')) forms.add(w.slice(0, -2));
|
|
244
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
|
+
}
|
|
245
273
|
return forms;
|
|
246
274
|
}
|
|
247
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
|
+
|
|
248
291
|
/**
|
|
249
292
|
* Whether two lowercase words are the same word, up to plural and stem form.
|
|
250
293
|
* @param {string} a
|
|
@@ -285,9 +328,201 @@ function wordsOf(text) {
|
|
|
285
328
|
function startsAWordOf(term, text) {
|
|
286
329
|
if (term.length < 4) return false;
|
|
287
330
|
if (term.length / String(text).length < 0.5) return false;
|
|
288
|
-
|
|
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();
|
|
289
353
|
}
|
|
290
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;
|
|
485
|
+
}
|
|
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
|
+
|
|
291
526
|
/**
|
|
292
527
|
* The fewest letters both words need before an edit distance counts as a
|
|
293
528
|
* typo, by distance. Below them, one edit usually makes a different word.
|
|
@@ -500,19 +735,20 @@ const STRONG_TOKEN_SCORE = 70;
|
|
|
500
735
|
* typography/font-setup, `side panel` is "Side panels");
|
|
501
736
|
* - 1: a word of the query is the topic's name (`illustration` in a longer
|
|
502
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);
|
|
503
740
|
* - 1: the query holds one of the doc's titles whole (`resizable side panels`
|
|
504
741
|
* names "Side panels"; `light dark mode button` names "Light/Dark Mode");
|
|
505
742
|
* - 1: the doc matches every word of the query and one of them is a word of
|
|
506
743
|
* its title (`switch to a dark theme` and "Use a theme").
|
|
507
744
|
* A section answers to its topic's name.
|
|
508
745
|
*
|
|
509
|
-
* A doc that matched only by
|
|
746
|
+
* A doc that matched only by a heading holding the query, by one word, or by
|
|
510
747
|
* words spread through its text has no priority. Docs are split into many
|
|
511
|
-
* small topics,
|
|
512
|
-
*
|
|
513
|
-
*
|
|
514
|
-
*
|
|
515
|
-
* 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
|
|
516
752
|
* in their text the same way. The score stays the text-match strength the
|
|
517
753
|
* result reports, so callers that gate on it (`build`) see the same numbers.
|
|
518
754
|
*
|
|
@@ -523,7 +759,13 @@ const STRONG_TOKEN_SCORE = 70;
|
|
|
523
759
|
* candidate's scoreQuery result.
|
|
524
760
|
* @returns {0 | 1 | 2}
|
|
525
761
|
*/
|
|
526
|
-
export function domainPriority(
|
|
762
|
+
export function domainPriority(
|
|
763
|
+
term,
|
|
764
|
+
tokens,
|
|
765
|
+
candidate,
|
|
766
|
+
hit,
|
|
767
|
+
queryWords = phraseWords(term),
|
|
768
|
+
) {
|
|
527
769
|
const words = [term, ...tokens];
|
|
528
770
|
if (candidate.domain === 'doc') {
|
|
529
771
|
const topic = String(candidate._topic ?? candidate.name).toLowerCase();
|
|
@@ -538,6 +780,20 @@ export function domainPriority(term, tokens, candidate, hit) {
|
|
|
538
780
|
if (named.some(n => samePhrase(term, n))) {
|
|
539
781
|
return 2;
|
|
540
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
|
+
}
|
|
541
797
|
if (
|
|
542
798
|
words.some(
|
|
543
799
|
w =>
|
|
@@ -568,6 +824,12 @@ export function domainPriority(term, tokens, candidate, hit) {
|
|
|
568
824
|
return 0;
|
|
569
825
|
}
|
|
570
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
|
+
}
|
|
571
833
|
const fuzzy = tokens.length <= 1;
|
|
572
834
|
return words.some(
|
|
573
835
|
w =>
|
|
@@ -683,14 +945,24 @@ export function titleInQuery(term, titles) {
|
|
|
683
945
|
* @param {string} term - Lowercased full query.
|
|
684
946
|
* @param {string[]} tokens - Content tokens from tokenizeQuery(term).
|
|
685
947
|
* @param {Candidate} candidate
|
|
686
|
-
* @
|
|
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}
|
|
687
953
|
* `matched`/`total` are the query concepts this candidate answered, out of
|
|
688
954
|
* the concepts the query had. Callers that must distinguish "matched one word
|
|
689
955
|
* of three" from "matched all three" — `build`, which gates its pages group
|
|
690
956
|
* on coverage — cannot recover that from the score, because a single strong
|
|
691
957
|
* hit and a broad weak one land on the same number.
|
|
692
958
|
*/
|
|
693
|
-
export function scoreQuery(
|
|
959
|
+
export function scoreQuery(
|
|
960
|
+
term,
|
|
961
|
+
tokens,
|
|
962
|
+
candidate,
|
|
963
|
+
words = phraseWords(term),
|
|
964
|
+
{plain = false} = {},
|
|
965
|
+
) {
|
|
694
966
|
const total = Math.max(tokens.length, 1);
|
|
695
967
|
// A whole-phrase hit answered the whole query by definition.
|
|
696
968
|
const asFull = (/** @type {{score: number, reason: string}} */ hit) => ({
|
|
@@ -699,14 +971,24 @@ export function scoreQuery(term, tokens, candidate) {
|
|
|
699
971
|
total,
|
|
700
972
|
});
|
|
701
973
|
// Typo tolerance is for one-word lookups. In a multi-word query a near miss
|
|
702
|
-
// is usually a different word, not a typo.
|
|
703
|
-
|
|
704
|
-
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
|
+
});
|
|
705
981
|
// A query of several words keeps its phrase tiers below even when stopwords
|
|
706
982
|
// leave one content word: "make an integration" is still the phrase an
|
|
707
983
|
// author declares as a keyword, and "build an integration" still names a
|
|
708
984
|
// title outright, though each tokenizes to `integration` alone.
|
|
709
|
-
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
|
+
}
|
|
710
992
|
|
|
711
993
|
/** 0–1 content tokens: whole-phrase fuzzy matching (typo tolerance for
|
|
712
994
|
* single words), but if stopwords left exactly one DIFFERENT token (e.g.
|
|
@@ -731,7 +1013,11 @@ export function scoreQuery(term, tokens, candidate) {
|
|
|
731
1013
|
// of Table-related templates each match "table" and "contents" separately
|
|
732
1014
|
// and accumulate a higher raw score (#5239).
|
|
733
1015
|
if (full && full.score >= 90) {
|
|
734
|
-
return asFull({
|
|
1016
|
+
return asFull({
|
|
1017
|
+
score: full.score + 100,
|
|
1018
|
+
reason: full.reason,
|
|
1019
|
+
...(full.alias ? {alias: full.alias, aliasWords: words.length} : {}),
|
|
1020
|
+
});
|
|
735
1021
|
}
|
|
736
1022
|
|
|
737
1023
|
// The whole query standing as a phrase in a doc's title or one of its
|
|
@@ -757,8 +1043,25 @@ export function scoreQuery(term, tokens, candidate) {
|
|
|
757
1043
|
let tokenSum = 0;
|
|
758
1044
|
/** @type {string[]} */
|
|
759
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;
|
|
760
1053
|
for (const tok of tokens) {
|
|
761
|
-
|
|
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
|
+
}
|
|
762
1065
|
if (h && h.score >= MIN_TOKEN_SCORE) {
|
|
763
1066
|
if (h.score > strongest) strongest = h.score;
|
|
764
1067
|
matched++;
|
|
@@ -808,6 +1111,7 @@ export function scoreQuery(term, tokens, candidate) {
|
|
|
808
1111
|
reason,
|
|
809
1112
|
matched,
|
|
810
1113
|
total,
|
|
1114
|
+
...(alias ? {alias, aliasWords} : {}),
|
|
811
1115
|
};
|
|
812
1116
|
}
|
|
813
1117
|
|
|
@@ -833,7 +1137,13 @@ export function scoreQuery(term, tokens, candidate) {
|
|
|
833
1137
|
strongest + Math.min(matched - 1, 3) * 12 + coverage * 15,
|
|
834
1138
|
);
|
|
835
1139
|
if (full && full.score >= tokenScore) return asFull(full);
|
|
836
|
-
return {
|
|
1140
|
+
return {
|
|
1141
|
+
score: tokenScore,
|
|
1142
|
+
reason,
|
|
1143
|
+
matched,
|
|
1144
|
+
total,
|
|
1145
|
+
...(alias ? {alias, aliasWords} : {}),
|
|
1146
|
+
};
|
|
837
1147
|
}
|
|
838
1148
|
|
|
839
1149
|
/**
|
|
@@ -852,8 +1162,9 @@ export function scoreQuery(term, tokens, candidate) {
|
|
|
852
1162
|
* @param {string} [candidate.description]
|
|
853
1163
|
* @param {string[]} [candidate.prose] - Extra free-text blobs (doc section text, best practices).
|
|
854
1164
|
* @param {string[]} [candidate.guidance] - Usage guidance (features, best practices) — scored a tier below description.
|
|
855
|
-
* @param {{fuzzy?: boolean}} [opts] - `fuzzy`: allow edit-distance (typo) matches. Default true; multi-word queries pass false.
|
|
856
|
-
* @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.
|
|
857
1168
|
*/
|
|
858
1169
|
export function scoreCandidate(
|
|
859
1170
|
term,
|
|
@@ -867,18 +1178,23 @@ export function scoreCandidate(
|
|
|
867
1178
|
prose = [],
|
|
868
1179
|
guidance = [],
|
|
869
1180
|
},
|
|
870
|
-
{fuzzy = true} = {},
|
|
1181
|
+
{fuzzy = true, joins = true} = {},
|
|
871
1182
|
) {
|
|
872
1183
|
let best = 0;
|
|
873
1184
|
let reason = '';
|
|
1185
|
+
/** @type {'partial' | 'keyword' | false} */
|
|
1186
|
+
let alias = false;
|
|
874
1187
|
/**
|
|
875
1188
|
* @param {number} score
|
|
876
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
|
|
877
1192
|
*/
|
|
878
|
-
const consider = (score, why) => {
|
|
1193
|
+
const consider = (score, why, byAlias = false) => {
|
|
879
1194
|
if (score > best) {
|
|
880
1195
|
best = score;
|
|
881
1196
|
reason = why;
|
|
1197
|
+
alias = byAlias;
|
|
882
1198
|
}
|
|
883
1199
|
};
|
|
884
1200
|
|
|
@@ -902,6 +1218,16 @@ export function scoreCandidate(
|
|
|
902
1218
|
nameLower === term.replace(/\s+/g, '');
|
|
903
1219
|
if (nameLower === term || leafLower === term || spelled) {
|
|
904
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');
|
|
905
1231
|
} else if (pluralOf(nameLower, term) || pluralOf(term, nameLower)) {
|
|
906
1232
|
// One point under the exact spelling, so the doc named `tokens` still
|
|
907
1233
|
// outranks the Token component for `tokens`.
|
|
@@ -925,12 +1251,27 @@ export function scoreCandidate(
|
|
|
925
1251
|
}
|
|
926
1252
|
|
|
927
1253
|
// ── Keyword signals ─────────────────────────────────────────────
|
|
1254
|
+
const termJoined = joined(term);
|
|
928
1255
|
for (const kw of keywords) {
|
|
929
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.
|
|
930
1262
|
if (kwLower === term) {
|
|
931
1263
|
consider(90, `keyword "${kw}"`);
|
|
932
1264
|
continue;
|
|
933
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
|
+
}
|
|
934
1275
|
if (sameWord(term, kwLower)) {
|
|
935
1276
|
consider(88, `keyword "${kw}"`);
|
|
936
1277
|
continue;
|
|
@@ -962,9 +1303,12 @@ export function scoreCandidate(
|
|
|
962
1303
|
// Match the term's stem as a whole word, tolerating plural/gerund suffixes
|
|
963
1304
|
// so "chart" matches "charts" and "filter" matches "filtering".
|
|
964
1305
|
if (term.length >= 3) {
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
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`);
|
|
968
1312
|
if (description && re.test(description.toLowerCase())) {
|
|
969
1313
|
consider(50, `description mentions "${term}"`);
|
|
970
1314
|
} else {
|
|
@@ -990,7 +1334,7 @@ export function scoreCandidate(
|
|
|
990
1334
|
}
|
|
991
1335
|
}
|
|
992
1336
|
|
|
993
|
-
return best > 0 ? {score: best, reason} : null;
|
|
1337
|
+
return best > 0 ? {score: best, reason, ...(alias ? {alias} : {})} : null;
|
|
994
1338
|
}
|
|
995
1339
|
|
|
996
1340
|
/**
|
|
@@ -1079,7 +1423,11 @@ async function gatherCoreComponents(coreDir) {
|
|
|
1079
1423
|
/** @type {string[]} */
|
|
1080
1424
|
let guidance = [];
|
|
1081
1425
|
if (readme && readme.endsWith('.doc.mjs')) {
|
|
1082
|
-
const
|
|
1426
|
+
const loaded = await loadModuleDoc(readme);
|
|
1427
|
+
// A member documented in its family's doc (VStack in Stack's doc) is
|
|
1428
|
+
// indexed from its own entry: the family's keywords and guidance
|
|
1429
|
+
// describe the family, not the member.
|
|
1430
|
+
const doc = familyMember(loaded, comp) ?? loaded;
|
|
1083
1431
|
if (doc) {
|
|
1084
1432
|
keywords = Array.isArray(doc.keywords) ? doc.keywords : [];
|
|
1085
1433
|
description = doc.usage?.description || doc.description || '';
|
|
@@ -1105,20 +1453,57 @@ async function gatherCoreComponents(coreDir) {
|
|
|
1105
1453
|
* usage/description from each component's .doc.mjs, same as core. Without
|
|
1106
1454
|
* this, an integration component is invisible to `search`/`build` even
|
|
1107
1455
|
* though `component --list`/`component <Name>` already resolve it — the two
|
|
1108
|
-
* discovery paths silently disagreed.
|
|
1456
|
+
* discovery paths silently disagreed. Also returns, per name, the docs that
|
|
1457
|
+
* hold it by their file name and the loadable docs that only record it.
|
|
1109
1458
|
* @param {import('../../foundation/integrations/integrations.mjs').LoadedIntegration[]} loadedIntegrations
|
|
1110
|
-
* @returns {Promise<Candidate[]>}
|
|
1459
|
+
* @returns {Promise<{candidates: Candidate[], fileNamed: Map<string, Set<string>>, documented: Map<string, Set<string>>}>}
|
|
1111
1460
|
*/
|
|
1112
1461
|
async function gatherIntegrationComponents(loadedIntegrations) {
|
|
1113
1462
|
/** @type {Candidate[]} */
|
|
1114
1463
|
const candidates = [];
|
|
1464
|
+
// What the owner rule reads: the docs that hold a name by their file name,
|
|
1465
|
+
// loadable or not and hidden ones too, and the loadable docs that only
|
|
1466
|
+
// record it.
|
|
1467
|
+
/** @type {Map<string, Set<string>>} */
|
|
1468
|
+
const fileNamed = new Map();
|
|
1469
|
+
/** @type {Map<string, Set<string>>} */
|
|
1470
|
+
const documented = new Map();
|
|
1471
|
+
/** @param {Map<string, Set<string>>} map @param {string} name @param {string} docPath */
|
|
1472
|
+
const hold = (map, name, docPath) =>
|
|
1473
|
+
map.set(name, (map.get(name) ?? new Set()).add(docPath));
|
|
1115
1474
|
for (const integration of loadedIntegrations) {
|
|
1116
|
-
const {components} =
|
|
1475
|
+
const {components, discovered} =
|
|
1476
|
+
await discoverValidIntegrationComponents(integration);
|
|
1477
|
+
const renamed = new Set(
|
|
1478
|
+
discovered
|
|
1479
|
+
.filter(rec => integrationRecordHold(rec) === 'doc')
|
|
1480
|
+
.filter(rec => !isIntegrationMember(rec))
|
|
1481
|
+
.map(rec => rec.docPath),
|
|
1482
|
+
);
|
|
1483
|
+
forEachIntegrationDoc(integration.components, (docPath, stem) => {
|
|
1484
|
+
if (!renamed.has(docPath)) hold(fileNamed, stem, docPath);
|
|
1485
|
+
});
|
|
1117
1486
|
for (const rec of components) {
|
|
1118
|
-
const
|
|
1487
|
+
const loaded = await loadModuleDoc(rec.docPath);
|
|
1488
|
+
// A family member is indexed from its own entry: the family's keywords
|
|
1489
|
+
// and guidance describe the family.
|
|
1490
|
+
const member = isIntegrationMember(rec);
|
|
1491
|
+
const doc = member ? integrationMemberEntry(loaded, rec) : loaded;
|
|
1492
|
+
// A doc that names another export of its file still answers to the
|
|
1493
|
+
// file's name, as `component <file name>` does.
|
|
1494
|
+
const fileName = docStem(rec.docPath);
|
|
1495
|
+
if (integrationRecordHold(rec) === 'doc') {
|
|
1496
|
+
hold(documented, rec.name, rec.docPath);
|
|
1497
|
+
}
|
|
1498
|
+
if (renamed.has(rec.docPath) && !member) {
|
|
1499
|
+
hold(documented, fileName, rec.docPath);
|
|
1500
|
+
}
|
|
1119
1501
|
candidates.push({
|
|
1120
1502
|
domain: 'component',
|
|
1121
1503
|
name: rec.name,
|
|
1504
|
+
aliases: !member && fileName !== rec.name ? [fileName] : [],
|
|
1505
|
+
_hold: integrationRecordHold(rec),
|
|
1506
|
+
_docPath: rec.docPath,
|
|
1122
1507
|
keywords: doc && Array.isArray(doc.keywords) ? doc.keywords : [],
|
|
1123
1508
|
description: doc ? doc.usage?.description || doc.description || '' : '',
|
|
1124
1509
|
guidance: guidanceFrom(doc),
|
|
@@ -1138,12 +1523,12 @@ async function gatherIntegrationComponents(loadedIntegrations) {
|
|
|
1138
1523
|
packageName: rec.package,
|
|
1139
1524
|
},
|
|
1140
1525
|
rec.name,
|
|
1141
|
-
|
|
1526
|
+
loaded?.import,
|
|
1142
1527
|
),
|
|
1143
1528
|
});
|
|
1144
1529
|
}
|
|
1145
1530
|
}
|
|
1146
|
-
return candidates;
|
|
1531
|
+
return {candidates, fileNamed, documented};
|
|
1147
1532
|
}
|
|
1148
1533
|
|
|
1149
1534
|
/**
|
|
@@ -1155,11 +1540,12 @@ async function gatherIntegrationComponents(loadedIntegrations) {
|
|
|
1155
1540
|
*/
|
|
1156
1541
|
async function gatherComponents(coreDir, cwd) {
|
|
1157
1542
|
const loadedIntegrations = await loadIntegrationsSafely(cwd);
|
|
1158
|
-
const [core,
|
|
1543
|
+
const [core, gathered, replacements] = await Promise.all([
|
|
1159
1544
|
gatherCoreComponents(coreDir),
|
|
1160
1545
|
gatherIntegrationComponents(loadedIntegrations),
|
|
1161
1546
|
loadComponentReplacements(coreDir, loadedIntegrations),
|
|
1162
1547
|
]);
|
|
1548
|
+
const {candidates: integrations, fileNamed, documented} = gathered;
|
|
1163
1549
|
// An active replacement answers to the Core name it replaces, so a search
|
|
1164
1550
|
// for that name finds the replacement and not the Core original
|
|
1165
1551
|
// (spec:AST-035 FR11).
|
|
@@ -1170,9 +1556,43 @@ async function gatherComponents(coreDir, cwd) {
|
|
|
1170
1556
|
active.target,
|
|
1171
1557
|
]),
|
|
1172
1558
|
);
|
|
1559
|
+
// The owner rule, as component detail applies it: a candidate `component
|
|
1560
|
+
// <name>` does not open names its package and follows the owner, and a
|
|
1561
|
+
// file-name alias that opens another owner is dropped.
|
|
1562
|
+
const coreNames = new Set(core.map(candidate => candidate.name));
|
|
1563
|
+
/** @param {string} name @param {Candidate} candidate */
|
|
1564
|
+
const opens = (name, candidate) =>
|
|
1565
|
+
!coreNames.has(name) &&
|
|
1566
|
+
findComponentReadme(coreDir, name) == null &&
|
|
1567
|
+
[...(fileNamed.get(name) ?? [])].every(doc => doc === candidate._docPath) &&
|
|
1568
|
+
[...(documented.get(name) ?? [])].every(doc => doc === candidate._docPath);
|
|
1569
|
+
// A legacy docs package keeps an exact name over an export name a doc records.
|
|
1570
|
+
/** @type {ReturnType<typeof discoverExternalPackages> | undefined} */
|
|
1571
|
+
let externals;
|
|
1572
|
+
/** @param {string} name */
|
|
1573
|
+
const legacyDocuments = name =>
|
|
1574
|
+
(externals ??= discoverExternalPackages(cwd)).some(
|
|
1575
|
+
ext => resolveLegacyExternalDoc(ext, name) != null,
|
|
1576
|
+
);
|
|
1577
|
+
const ruled = integrations.map(candidate => {
|
|
1578
|
+
const aliases = (candidate.aliases ?? []).filter(alias =>
|
|
1579
|
+
opens(alias, candidate),
|
|
1580
|
+
);
|
|
1581
|
+
return candidate._hold === 'doc' &&
|
|
1582
|
+
(!opens(candidate.name, candidate) || legacyDocuments(candidate.name))
|
|
1583
|
+
? {
|
|
1584
|
+
...candidate,
|
|
1585
|
+
aliases,
|
|
1586
|
+
_command: `astryx component ${candidate.name} --package ${candidate._package}`,
|
|
1587
|
+
}
|
|
1588
|
+
: {...candidate, aliases};
|
|
1589
|
+
});
|
|
1173
1590
|
return [
|
|
1174
1591
|
...core.filter(candidate => !replacements.forTarget(candidate.name)),
|
|
1175
|
-
...
|
|
1592
|
+
...[
|
|
1593
|
+
...ruled.filter(candidate => !candidate._command),
|
|
1594
|
+
...ruled.filter(candidate => candidate._command),
|
|
1595
|
+
].map(candidate => {
|
|
1176
1596
|
const target = targetOf.get(`${candidate._package}\0${candidate.name}`);
|
|
1177
1597
|
if (target != null) {
|
|
1178
1598
|
return {...candidate, aliases: [...(candidate.aliases ?? []), target]};
|
|
@@ -1225,11 +1645,11 @@ export async function componentKeywords(coreDir, cwd) {
|
|
|
1225
1645
|
.flat()
|
|
1226
1646
|
.map(async name => {
|
|
1227
1647
|
const readme = findComponentReadme(coreDir, name);
|
|
1228
|
-
const
|
|
1648
|
+
const loaded =
|
|
1229
1649
|
readme && readme.endsWith('.doc.mjs')
|
|
1230
1650
|
? await loadModuleDoc(readme)
|
|
1231
1651
|
: null;
|
|
1232
|
-
return {name, keywords: keywordsOf(
|
|
1652
|
+
return {name, keywords: keywordsOf(familyMember(loaded, name) ?? loaded)};
|
|
1233
1653
|
});
|
|
1234
1654
|
const loadedIntegrations = await loadIntegrationsSafely(cwd);
|
|
1235
1655
|
const replacements = await loadComponentReplacements(
|
|
@@ -1239,10 +1659,13 @@ export async function componentKeywords(coreDir, cwd) {
|
|
|
1239
1659
|
const integrations = loadedIntegrations.map(async integration => {
|
|
1240
1660
|
const {components} = await discoverValidIntegrationComponents(integration);
|
|
1241
1661
|
return Promise.all(
|
|
1242
|
-
components.map(async rec =>
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1662
|
+
components.map(async rec => {
|
|
1663
|
+
const loaded = await loadModuleDoc(rec.docPath);
|
|
1664
|
+
return {
|
|
1665
|
+
name: rec.name,
|
|
1666
|
+
keywords: keywordsOf(integrationMemberEntry(loaded, rec) ?? loaded),
|
|
1667
|
+
};
|
|
1668
|
+
}),
|
|
1246
1669
|
);
|
|
1247
1670
|
});
|
|
1248
1671
|
return [
|
|
@@ -1416,6 +1839,10 @@ async function gatherDocs(cwd) {
|
|
|
1416
1839
|
...defined,
|
|
1417
1840
|
...codeTerms({content}),
|
|
1418
1841
|
],
|
|
1842
|
+
_declared: [
|
|
1843
|
+
...(Array.isArray(selfDoc?.keywords) ? selfDoc.keywords : []),
|
|
1844
|
+
...(Array.isArray(node.keywords) ? node.keywords : []),
|
|
1845
|
+
],
|
|
1419
1846
|
description: node.summary || '',
|
|
1420
1847
|
prose: sectionProse({title: node.title, content}),
|
|
1421
1848
|
titles: [node.title],
|
|
@@ -1552,6 +1979,7 @@ function topicCandidates(
|
|
|
1552
1979
|
...(doc?.title || title ? [doc?.title || title] : []),
|
|
1553
1980
|
...(Array.isArray(doc?.keywords) ? doc.keywords : []),
|
|
1554
1981
|
],
|
|
1982
|
+
_declared: Array.isArray(doc?.keywords) ? doc.keywords : [],
|
|
1555
1983
|
description: doc?.description || summary,
|
|
1556
1984
|
prose: split
|
|
1557
1985
|
? sections.map(section => section.title).filter(Boolean)
|
|
@@ -1811,8 +2239,6 @@ async function searchOnce(query, options) {
|
|
|
1811
2239
|
}
|
|
1812
2240
|
|
|
1813
2241
|
const term = String(query).trim().toLowerCase();
|
|
1814
|
-
const tokens = tokenizeQuery(term);
|
|
1815
|
-
|
|
1816
2242
|
// `astryx docs` reads docs without @astryxdesign/core, and `astryx theme
|
|
1817
2243
|
// list` reads themes without it (bundled themes need no project), so a
|
|
1818
2244
|
// search of either must too. Every other domain reads core: asked for by
|
|
@@ -1844,14 +2270,100 @@ async function searchOnce(query, options) {
|
|
|
1844
2270
|
|
|
1845
2271
|
const all = [...components, ...hooks, ...docTopics, ...templates, ...themes];
|
|
1846
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
|
+
|
|
1847
2359
|
// Score every candidate on its own merits. The consumer groups results by
|
|
1848
2360
|
// role (page / block / component) and takes the top of each, so there's no
|
|
1849
2361
|
// cross-role competition to engineer — a target page only needs to be the
|
|
1850
2362
|
// strongest PAGE, not outrank every component.
|
|
1851
|
-
/** @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}[]} */
|
|
1852
2364
|
const ranked = [];
|
|
1853
2365
|
for (const candidate of all) {
|
|
1854
|
-
const hit = scoreQuery(term, tokens, candidate);
|
|
2366
|
+
const hit = scoreQuery(term, tokens, candidate, words);
|
|
1855
2367
|
if (hit)
|
|
1856
2368
|
ranked.push({
|
|
1857
2369
|
result: toResult(
|
|
@@ -1861,9 +2373,54 @@ async function searchOnce(query, options) {
|
|
|
1861
2373
|
hit.matched,
|
|
1862
2374
|
hit.total,
|
|
1863
2375
|
),
|
|
1864
|
-
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),
|
|
1865
2383
|
});
|
|
1866
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
|
+
}
|
|
1867
2424
|
|
|
1868
2425
|
// Docs and everything else are each sorted by score desc, then domain
|
|
1869
2426
|
// (stable order), then name. The two are merged: at each step the stronger
|
|
@@ -1872,11 +2429,11 @@ async function searchOnce(query, options) {
|
|
|
1872
2429
|
/** @type {Record<string, number>} */
|
|
1873
2430
|
const domainOrder = {component: 0, hook: 1, doc: 2, template: 3, theme: 4};
|
|
1874
2431
|
/**
|
|
1875
|
-
* @param {{result: any}} x
|
|
1876
|
-
* @param {{result: any}} y
|
|
2432
|
+
* @param {{result: any, key: number}} x
|
|
2433
|
+
* @param {{result: any, key: number}} y
|
|
1877
2434
|
*/
|
|
1878
|
-
const byScore = ({result: a}, {result: b}) =>
|
|
1879
|
-
|
|
2435
|
+
const byScore = ({result: a, key: ka}, {result: b, key: kb}) =>
|
|
2436
|
+
kb - ka ||
|
|
1880
2437
|
(domainOrder[a.domain] ?? 9) - (domainOrder[b.domain] ?? 9) ||
|
|
1881
2438
|
a.name.localeCompare(b.name);
|
|
1882
2439
|
const others = ranked.filter(r => r.result.domain !== 'doc').sort(byScore);
|
|
@@ -1929,5 +2486,5 @@ async function searchOnce(query, options) {
|
|
|
1929
2486
|
components.map(c => ({name: c.name, keywords: c.keywords ?? []})),
|
|
1930
2487
|
);
|
|
1931
2488
|
}
|
|
1932
|
-
return response;
|
|
2489
|
+
return linkSearchResponse(response, cwd);
|
|
1933
2490
|
}
|