@mfdaves/okf-mcp 0.9.1 → 0.13.0-rc.1

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.
Files changed (115) hide show
  1. package/CHANGELOG.md +100 -0
  2. package/README.md +452 -26
  3. package/bin/okf-mcp.js +6 -1
  4. package/okf/okf-mcp/distribution/reference-bundle.md +10 -3
  5. package/okf/okf-mcp/index.md +2 -1
  6. package/okf/okf-mcp/interfaces/http-authoring-api.md +11 -2
  7. package/okf/okf-mcp/interfaces/mcp-http.md +64 -0
  8. package/okf/okf-mcp/interfaces/mcp-tools.md +25 -6
  9. package/okf/okf-mcp/overview/okf-mcp.md +16 -6
  10. package/okf/okf-mcp/policies/authoring-safety.md +28 -5
  11. package/okf/okf-mcp/runtime/indexer.md +14 -1
  12. package/okf/okf-mcp/runtime/mcp-server.md +16 -8
  13. package/okf/okf-mcp/specs/producer-api.md +16 -2
  14. package/package.json +17 -5
  15. package/server.json +38 -2
  16. package/src/assets.js +165 -73
  17. package/src/authoring/candidates.js +434 -0
  18. package/src/authoring/git-preflight.js +225 -0
  19. package/src/authoring/git-publish.js +783 -0
  20. package/src/authoring/live.js +757 -0
  21. package/src/authoring/paths.js +112 -0
  22. package/src/authoring/policy-hook.js +221 -0
  23. package/src/authoring/proposal-policy.js +159 -0
  24. package/src/authoring/receipts.js +373 -0
  25. package/src/authoring/render.js +38 -0
  26. package/src/authoring/shared.js +75 -0
  27. package/src/authoring/staging.js +216 -0
  28. package/src/authoring.js +386 -287
  29. package/src/cache/files.js +147 -0
  30. package/src/cache/lock.js +201 -0
  31. package/src/cache/paths.js +197 -0
  32. package/src/cache/store.js +703 -0
  33. package/src/catalog-text.js +19 -0
  34. package/src/cli/commands.js +448 -0
  35. package/src/cli/http-options.js +193 -0
  36. package/src/cli/options.js +554 -0
  37. package/src/cli/usage.js +96 -0
  38. package/src/cli.js +18 -932
  39. package/src/computation.js +99 -61
  40. package/src/context/assemble.js +567 -0
  41. package/src/context/cli-options.js +88 -0
  42. package/src/context/score.js +234 -0
  43. package/src/context/sections.js +274 -0
  44. package/src/embed/interface.js +160 -0
  45. package/src/embed/openai.js +715 -0
  46. package/src/embed/prepare.js +182 -0
  47. package/src/embed/units.js +96 -0
  48. package/src/error-details.js +53 -0
  49. package/src/git-source.js +112 -52
  50. package/src/graph.js +95 -37
  51. package/src/http-server.js +36 -17
  52. package/src/index.js +15 -0
  53. package/src/indexer/assemble.js +566 -0
  54. package/src/indexer/build.js +290 -0
  55. package/src/indexer/cache.js +81 -0
  56. package/src/indexer/edges.js +430 -0
  57. package/src/indexer/index.js +44 -0
  58. package/src/indexer/paths.js +178 -0
  59. package/src/indexer/resolve.js +282 -0
  60. package/src/indexer/update.js +720 -0
  61. package/src/indexer.js +3 -1068
  62. package/src/live-authoring.js +4 -2329
  63. package/src/markdown.js +21 -16
  64. package/src/mcp/auth.js +409 -0
  65. package/src/mcp/http.js +317 -0
  66. package/src/mcp/principal.js +59 -0
  67. package/src/mcp/registry.js +356 -0
  68. package/src/mcp/resources.js +45 -0
  69. package/src/mcp/server.js +567 -0
  70. package/src/mcp/tools/catalog.js +247 -0
  71. package/src/mcp/tools/computation.js +83 -0
  72. package/src/mcp/tools/context.js +133 -0
  73. package/src/mcp/tools/graph.js +167 -0
  74. package/src/mcp/tools/live-authoring.js +316 -0
  75. package/src/mcp/tools/migration.js +86 -0
  76. package/src/mcp/tools/producers.js +79 -0
  77. package/src/mcp/tools/proposals.js +225 -0
  78. package/src/mcp/tools/provenance.js +87 -0
  79. package/src/mcp/tools/remote.js +79 -0
  80. package/src/mcp/tools/search.js +242 -0
  81. package/src/mcp-server.js +3 -1611
  82. package/src/migration.js +431 -253
  83. package/src/parser.js +245 -130
  84. package/src/plugins.js +71 -48
  85. package/src/policy/write-policy.js +713 -0
  86. package/src/producer-publisher.js +202 -78
  87. package/src/producers.js +311 -103
  88. package/src/project.js +346 -93
  89. package/src/remote.js +96 -61
  90. package/src/search/cli-options.js +107 -0
  91. package/src/search/confidence.js +61 -0
  92. package/src/search/dense.js +304 -0
  93. package/src/search/embedding-cli.js +57 -0
  94. package/src/search/embedding-config.js +217 -0
  95. package/src/search/fusion.js +249 -0
  96. package/src/search/hybrid.js +526 -0
  97. package/src/search/languages.js +200 -0
  98. package/src/search/lexical.js +695 -0
  99. package/src/search/query.js +620 -0
  100. package/src/search/stem/among.js +43 -0
  101. package/src/search/stem/base-stemmer.js +311 -0
  102. package/src/search/stem/en-regions.js +456 -0
  103. package/src/search/stem/en-suffixes.js +664 -0
  104. package/src/search/stem/en-tables.js +176 -0
  105. package/src/search/stem/en.js +238 -0
  106. package/src/search/stem/it-regions.js +459 -0
  107. package/src/search/stem/it-suffixes.js +471 -0
  108. package/src/search/stem/it-tables.js +257 -0
  109. package/src/search/stem/it.js +155 -0
  110. package/src/search-index.js +2 -81
  111. package/src/search.js +2 -252
  112. package/src/store.js +134 -81
  113. package/src/tool-packs.js +346 -0
  114. package/src/v02.js +301 -105
  115. package/src/validation.js +24 -20
@@ -0,0 +1,257 @@
1
+ /*
2
+ * Copyright (c) AXA Group Operations Spain S.A.
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining
5
+ * a copy of this software and associated documentation files (the
6
+ * 'Software'), to deal in the Software without restriction, including
7
+ * without limitation the rights to use, copy, modify, merge, publish,
8
+ * distribute, sublicense, and/or sell copies of the Software, and to
9
+ * permit persons to whom the Software is furnished to do so, subject to
10
+ * the following conditions:
11
+ *
12
+ * The above copyright notice and this permission notice shall be
13
+ * included in all copies or substantial portions of the Software.
14
+ *
15
+ * THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
16
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ */
23
+
24
+ // Provenance: derived from @nlpjs/lang-it 4.26.1, src/stemmer-it.js (MIT,
25
+ // header above), itself generated by the Snowball compiler from the
26
+ // Snowball Italian stemming algorithm; this file holds the suffix tables and character groupings.
27
+ // Mechanical changes only (scripts/vendor-stemmers.js): the class is split
28
+ // by routine group to stay under the 800-line cap, local requires replace
29
+ // @nlpjs/core, no container or tokenizer plumbing, strict equality,
30
+ // block-scoped and const declarations, labels renamed apart from their
31
+ // guard variables, Biome formatting. test/stem-parity.test.js pins zero
32
+ // disagreements with the upstream package.
33
+ "use strict";
34
+ const Among = require("./among");
35
+
36
+ const tables = {};
37
+
38
+ tables.a_0 = [
39
+ new Among("", -1, 7),
40
+ new Among("qu", 0, 6),
41
+ new Among("\u00E1", 0, 1),
42
+ new Among("\u00E9", 0, 2),
43
+ new Among("\u00ED", 0, 3),
44
+ new Among("\u00F3", 0, 4),
45
+ new Among("\u00FA", 0, 5),
46
+ ];
47
+
48
+ tables.a_1 = [new Among("", -1, 3), new Among("I", 0, 1), new Among("U", 0, 2)];
49
+
50
+ tables.a_2 = [
51
+ new Among("la", -1, -1),
52
+ new Among("cela", 0, -1),
53
+ new Among("gliela", 0, -1),
54
+ new Among("mela", 0, -1),
55
+ new Among("tela", 0, -1),
56
+ new Among("vela", 0, -1),
57
+ new Among("le", -1, -1),
58
+ new Among("cele", 6, -1),
59
+ new Among("gliele", 6, -1),
60
+ new Among("mele", 6, -1),
61
+ new Among("tele", 6, -1),
62
+ new Among("vele", 6, -1),
63
+ new Among("ne", -1, -1),
64
+ new Among("cene", 12, -1),
65
+ new Among("gliene", 12, -1),
66
+ new Among("mene", 12, -1),
67
+ new Among("sene", 12, -1),
68
+ new Among("tene", 12, -1),
69
+ new Among("vene", 12, -1),
70
+ new Among("ci", -1, -1),
71
+ new Among("li", -1, -1),
72
+ new Among("celi", 20, -1),
73
+ new Among("glieli", 20, -1),
74
+ new Among("meli", 20, -1),
75
+ new Among("teli", 20, -1),
76
+ new Among("veli", 20, -1),
77
+ new Among("gli", 20, -1),
78
+ new Among("mi", -1, -1),
79
+ new Among("si", -1, -1),
80
+ new Among("ti", -1, -1),
81
+ new Among("vi", -1, -1),
82
+ new Among("lo", -1, -1),
83
+ new Among("celo", 31, -1),
84
+ new Among("glielo", 31, -1),
85
+ new Among("melo", 31, -1),
86
+ new Among("telo", 31, -1),
87
+ new Among("velo", 31, -1),
88
+ ];
89
+
90
+ tables.a_3 = [
91
+ new Among("ando", -1, 1),
92
+ new Among("endo", -1, 1),
93
+ new Among("ar", -1, 2),
94
+ new Among("er", -1, 2),
95
+ new Among("ir", -1, 2),
96
+ ];
97
+
98
+ tables.a_4 = [
99
+ new Among("ic", -1, -1),
100
+ new Among("abil", -1, -1),
101
+ new Among("os", -1, -1),
102
+ new Among("iv", -1, 1),
103
+ ];
104
+
105
+ tables.a_5 = [new Among("ic", -1, 1), new Among("abil", -1, 1), new Among("iv", -1, 1)];
106
+
107
+ tables.a_6 = [
108
+ new Among("ica", -1, 1),
109
+ new Among("logia", -1, 3),
110
+ new Among("osa", -1, 1),
111
+ new Among("ista", -1, 1),
112
+ new Among("iva", -1, 9),
113
+ new Among("anza", -1, 1),
114
+ new Among("enza", -1, 5),
115
+ new Among("ice", -1, 1),
116
+ new Among("atrice", 7, 1),
117
+ new Among("iche", -1, 1),
118
+ new Among("logie", -1, 3),
119
+ new Among("abile", -1, 1),
120
+ new Among("ibile", -1, 1),
121
+ new Among("usione", -1, 4),
122
+ new Among("azione", -1, 2),
123
+ new Among("uzione", -1, 4),
124
+ new Among("atore", -1, 2),
125
+ new Among("ose", -1, 1),
126
+ new Among("ante", -1, 1),
127
+ new Among("mente", -1, 1),
128
+ new Among("amente", 19, 7),
129
+ new Among("iste", -1, 1),
130
+ new Among("ive", -1, 9),
131
+ new Among("anze", -1, 1),
132
+ new Among("enze", -1, 5),
133
+ new Among("ici", -1, 1),
134
+ new Among("atrici", 25, 1),
135
+ new Among("ichi", -1, 1),
136
+ new Among("abili", -1, 1),
137
+ new Among("ibili", -1, 1),
138
+ new Among("ismi", -1, 1),
139
+ new Among("usioni", -1, 4),
140
+ new Among("azioni", -1, 2),
141
+ new Among("uzioni", -1, 4),
142
+ new Among("atori", -1, 2),
143
+ new Among("osi", -1, 1),
144
+ new Among("anti", -1, 1),
145
+ new Among("amenti", -1, 6),
146
+ new Among("imenti", -1, 6),
147
+ new Among("isti", -1, 1),
148
+ new Among("ivi", -1, 9),
149
+ new Among("ico", -1, 1),
150
+ new Among("ismo", -1, 1),
151
+ new Among("oso", -1, 1),
152
+ new Among("amento", -1, 6),
153
+ new Among("imento", -1, 6),
154
+ new Among("ivo", -1, 9),
155
+ new Among("it\u00E0", -1, 8),
156
+ new Among("ist\u00E0", -1, 1),
157
+ new Among("ist\u00E8", -1, 1),
158
+ new Among("ist\u00EC", -1, 1),
159
+ ];
160
+
161
+ tables.a_7 = [
162
+ new Among("isca", -1, 1),
163
+ new Among("enda", -1, 1),
164
+ new Among("ata", -1, 1),
165
+ new Among("ita", -1, 1),
166
+ new Among("uta", -1, 1),
167
+ new Among("ava", -1, 1),
168
+ new Among("eva", -1, 1),
169
+ new Among("iva", -1, 1),
170
+ new Among("erebbe", -1, 1),
171
+ new Among("irebbe", -1, 1),
172
+ new Among("isce", -1, 1),
173
+ new Among("ende", -1, 1),
174
+ new Among("are", -1, 1),
175
+ new Among("ere", -1, 1),
176
+ new Among("ire", -1, 1),
177
+ new Among("asse", -1, 1),
178
+ new Among("ate", -1, 1),
179
+ new Among("avate", 16, 1),
180
+ new Among("evate", 16, 1),
181
+ new Among("ivate", 16, 1),
182
+ new Among("ete", -1, 1),
183
+ new Among("erete", 20, 1),
184
+ new Among("irete", 20, 1),
185
+ new Among("ite", -1, 1),
186
+ new Among("ereste", -1, 1),
187
+ new Among("ireste", -1, 1),
188
+ new Among("ute", -1, 1),
189
+ new Among("erai", -1, 1),
190
+ new Among("irai", -1, 1),
191
+ new Among("isci", -1, 1),
192
+ new Among("endi", -1, 1),
193
+ new Among("erei", -1, 1),
194
+ new Among("irei", -1, 1),
195
+ new Among("assi", -1, 1),
196
+ new Among("ati", -1, 1),
197
+ new Among("iti", -1, 1),
198
+ new Among("eresti", -1, 1),
199
+ new Among("iresti", -1, 1),
200
+ new Among("uti", -1, 1),
201
+ new Among("avi", -1, 1),
202
+ new Among("evi", -1, 1),
203
+ new Among("ivi", -1, 1),
204
+ new Among("isco", -1, 1),
205
+ new Among("ando", -1, 1),
206
+ new Among("endo", -1, 1),
207
+ new Among("Yamo", -1, 1),
208
+ new Among("iamo", -1, 1),
209
+ new Among("avamo", -1, 1),
210
+ new Among("evamo", -1, 1),
211
+ new Among("ivamo", -1, 1),
212
+ new Among("eremo", -1, 1),
213
+ new Among("iremo", -1, 1),
214
+ new Among("assimo", -1, 1),
215
+ new Among("ammo", -1, 1),
216
+ new Among("emmo", -1, 1),
217
+ new Among("eremmo", 54, 1),
218
+ new Among("iremmo", 54, 1),
219
+ new Among("immo", -1, 1),
220
+ new Among("ano", -1, 1),
221
+ new Among("iscano", 58, 1),
222
+ new Among("avano", 58, 1),
223
+ new Among("evano", 58, 1),
224
+ new Among("ivano", 58, 1),
225
+ new Among("eranno", -1, 1),
226
+ new Among("iranno", -1, 1),
227
+ new Among("ono", -1, 1),
228
+ new Among("iscono", 65, 1),
229
+ new Among("arono", 65, 1),
230
+ new Among("erono", 65, 1),
231
+ new Among("irono", 65, 1),
232
+ new Among("erebbero", -1, 1),
233
+ new Among("irebbero", -1, 1),
234
+ new Among("assero", -1, 1),
235
+ new Among("essero", -1, 1),
236
+ new Among("issero", -1, 1),
237
+ new Among("ato", -1, 1),
238
+ new Among("ito", -1, 1),
239
+ new Among("uto", -1, 1),
240
+ new Among("avo", -1, 1),
241
+ new Among("evo", -1, 1),
242
+ new Among("ivo", -1, 1),
243
+ new Among("ar", -1, 1),
244
+ new Among("ir", -1, 1),
245
+ new Among("er\u00E0", -1, 1),
246
+ new Among("ir\u00E0", -1, 1),
247
+ new Among("er\u00F2", -1, 1),
248
+ new Among("ir\u00F2", -1, 1),
249
+ ];
250
+
251
+ tables.g_v = [17, 65, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 128, 8, 2, 1];
252
+
253
+ tables.g_AEIO = [17, 65, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 128, 8, 2];
254
+
255
+ tables.g_CG = [17];
256
+
257
+ module.exports = tables;
@@ -0,0 +1,155 @@
1
+ /*
2
+ * Copyright (c) AXA Group Operations Spain S.A.
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining
5
+ * a copy of this software and associated documentation files (the
6
+ * 'Software'), to deal in the Software without restriction, including
7
+ * without limitation the rights to use, copy, modify, merge, publish,
8
+ * distribute, sublicense, and/or sell copies of the Software, and to
9
+ * permit persons to whom the Software is furnished to do so, subject to
10
+ * the following conditions:
11
+ *
12
+ * The above copyright notice and this permission notice shall be
13
+ * included in all copies or substantial portions of the Software.
14
+ *
15
+ * THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
16
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ */
23
+
24
+ // Provenance: derived from @nlpjs/lang-it 4.26.1, src/stemmer-it.js (MIT,
25
+ // header above), itself generated by the Snowball compiler from the
26
+ // Snowball Italian stemming algorithm; this file holds the class with its entry point.
27
+ // Mechanical changes only (scripts/vendor-stemmers.js): the class is split
28
+ // by routine group to stay under the 800-line cap, local requires replace
29
+ // @nlpjs/core, no container or tokenizer plumbing, strict equality,
30
+ // block-scoped and const declarations, labels renamed apart from their
31
+ // guard variables, Biome formatting. test/stem-parity.test.js pins zero
32
+ // disagreements with the upstream package.
33
+ "use strict";
34
+ const BaseStemmer = require("./base-stemmer");
35
+
36
+ class StemmerIt extends BaseStemmer {
37
+ constructor() {
38
+ super();
39
+ this.name = "stemmer-it";
40
+ this.I_p2 = 0;
41
+ this.I_p1 = 0;
42
+ this.I_pV = 0;
43
+ }
44
+
45
+ r_R1() {
46
+ if (!(this.I_p1 <= this.cursor)) {
47
+ return false;
48
+ }
49
+ return true;
50
+ }
51
+
52
+ r_R2() {
53
+ if (!(this.I_p2 <= this.cursor)) {
54
+ return false;
55
+ }
56
+ return true;
57
+ }
58
+
59
+ innerStem() {
60
+ let v_5;
61
+ // (, line 181
62
+ // do, line 182
63
+ const v_1 = this.cursor;
64
+ let lab0 = true;
65
+ while (lab0 === true) {
66
+ lab0 = false;
67
+ // call prelude, line 182
68
+ if (!this.r_prelude()) {
69
+ break;
70
+ }
71
+ }
72
+ this.cursor = v_1;
73
+ // do, line 183
74
+ const v_2 = this.cursor;
75
+ let lab1 = true;
76
+ while (lab1 === true) {
77
+ lab1 = false;
78
+ // call mark_regions, line 183
79
+ if (!this.r_mark_regions()) {
80
+ break;
81
+ }
82
+ }
83
+ this.cursor = v_2;
84
+ // backwards, line 184
85
+ this.limit_backward = this.cursor;
86
+ this.cursor = this.limit;
87
+ // (, line 184
88
+ // do, line 185
89
+ const v_3 = this.limit - this.cursor;
90
+ let lab2 = true;
91
+ while (lab2 === true) {
92
+ lab2 = false;
93
+ // call attached_pronoun, line 185
94
+ if (!this.r_attached_pronoun()) {
95
+ break;
96
+ }
97
+ }
98
+ this.cursor = this.limit - v_3;
99
+ // do, line 186
100
+ const v_4 = this.limit - this.cursor;
101
+ let lab3 = true;
102
+ label3: while (lab3 === true) {
103
+ lab3 = false;
104
+ // (, line 186
105
+ // or, line 186
106
+ let lab4 = true;
107
+ label4: while (lab4 === true) {
108
+ lab4 = false;
109
+ v_5 = this.limit - this.cursor;
110
+ let lab5 = true;
111
+ while (lab5 === true) {
112
+ lab5 = false;
113
+ // call standard_suffix, line 186
114
+ if (!this.r_standard_suffix()) {
115
+ break;
116
+ }
117
+ break label4;
118
+ }
119
+ this.cursor = this.limit - v_5;
120
+ // call verb_suffix, line 186
121
+ if (!this.r_verb_suffix()) {
122
+ break label3;
123
+ }
124
+ }
125
+ }
126
+ this.cursor = this.limit - v_4;
127
+ // do, line 187
128
+ const v_6 = this.limit - this.cursor;
129
+ let lab6 = true;
130
+ while (lab6 === true) {
131
+ lab6 = false;
132
+ // call vowel_suffix, line 187
133
+ if (!this.r_vowel_suffix()) {
134
+ break;
135
+ }
136
+ }
137
+ this.cursor = this.limit - v_6;
138
+ this.cursor = this.limit_backward; // do, line 189
139
+ const v_7 = this.cursor;
140
+ let lab7 = true;
141
+ while (lab7 === true) {
142
+ lab7 = false;
143
+ // call postlude, line 189
144
+ if (!this.r_postlude()) {
145
+ break;
146
+ }
147
+ }
148
+ this.cursor = v_7;
149
+ return true;
150
+ }
151
+ }
152
+
153
+ Object.assign(StemmerIt.prototype, require("./it-regions"), require("./it-suffixes"));
154
+
155
+ module.exports = StemmerIt;
@@ -1,83 +1,4 @@
1
1
  "use strict";
2
2
 
3
- const MiniSearch = require("minisearch");
4
-
5
- const MAX_QUERY_CHARACTERS = 512;
6
- const MAX_QUERY_TERMS = 16;
7
- const SEARCH_FIELDS = Object.freeze([
8
- "title",
9
- "type",
10
- "tags",
11
- "aliases",
12
- "description",
13
- "path",
14
- "body",
15
- ]);
16
- const SEARCH_BOOSTS = Object.freeze({
17
- title: 8,
18
- type: 5,
19
- tags: 4,
20
- aliases: 4,
21
- description: 3,
22
- path: 2,
23
- body: 1,
24
- });
25
- const SEARCH_INDEXES = new WeakMap();
26
- const tokenize = MiniSearch.getDefault("tokenize");
27
- const processTerm = MiniSearch.getDefault("processTerm");
28
-
29
- function queryTerms(query) {
30
- return tokenize(String(query || ""))
31
- .map((term) => processTerm(term))
32
- .filter((term) => typeof term === "string" && term.length > 0);
33
- }
34
-
35
- function normalizeSearchQuery(value) {
36
- const query = String(value || "").trim();
37
- if (Array.from(query).length > MAX_QUERY_CHARACTERS) {
38
- throw new TypeError(`Search query must not exceed ${MAX_QUERY_CHARACTERS} characters.`);
39
- }
40
- const terms = queryTerms(query);
41
- if (terms.length > MAX_QUERY_TERMS) {
42
- throw new TypeError(`Search query must not exceed ${MAX_QUERY_TERMS} terms.`);
43
- }
44
- return { query, terms };
45
- }
46
-
47
- function searchDocument(doc) {
48
- return {
49
- id: doc.uri,
50
- title: String(doc.title || ""),
51
- type: String(doc.type || ""),
52
- tags: (doc.tags || []).join(" "),
53
- aliases: (doc.aliases || []).join(" "),
54
- description: String(doc.description || ""),
55
- path: String(doc.path || ""),
56
- body: String(doc.body || ""),
57
- };
58
- }
59
-
60
- function prepareSearchIndex(index) {
61
- let searchIndex = SEARCH_INDEXES.get(index);
62
- if (searchIndex) {
63
- return searchIndex;
64
- }
65
- searchIndex = new MiniSearch({
66
- fields: SEARCH_FIELDS,
67
- idField: "id",
68
- searchOptions: {
69
- boost: SEARCH_BOOSTS,
70
- combineWith: "AND",
71
- },
72
- });
73
- searchIndex.addAll(index.concepts.map(searchDocument));
74
- SEARCH_INDEXES.set(index, searchIndex);
75
- return searchIndex;
76
- }
77
-
78
- module.exports = {
79
- MAX_QUERY_CHARACTERS,
80
- MAX_QUERY_TERMS,
81
- normalizeSearchQuery,
82
- prepareSearchIndex,
83
- };
3
+ // Kept through 1.0 as a shim (plan section 6); the lexical index lives in search/lexical.js.
4
+ module.exports = require("./search/lexical");