@lde/search-pipeline 0.41.3 → 0.43.0

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.
@@ -69,6 +69,22 @@ export interface SearchIndexerPipelineOptions {
69
69
  * attaching nothing and shipping an unenriched collection.
70
70
  */
71
71
  transforms?: Readonly<Record<string, QuadTransform<ReaderContext> | QuadTransform<ReaderContext>[]>>;
72
+ /**
73
+ * A SPARQL graph pattern over `?root` per root type, keyed by
74
+ * {@link SearchType.name}, that restricts which of the type’s instances are
75
+ * indexed, in every dataset ({@link selectByClass}). A root left out is never
76
+ * extracted, so the collection and its facet counts hold only the roots that
77
+ * match. Types without an entry are indexed whole.
78
+ *
79
+ * References from a kept document to a left-out root stay as they are.
80
+ * A name the schema does not declare, a registry-sourced type (it describes
81
+ * the dataset, not its records), a pattern that does not mention `?root` or
82
+ * one that does not parse throws at wiring time. Write IRIs in full: the
83
+ * query declares no prefixes. The restrictions are part
84
+ * of the version a {@link provenanceStore} keys its skips by, so changing one
85
+ * re-indexes every dataset.
86
+ */
87
+ restrictRoots?: Readonly<Record<string, string>>;
72
88
  /**
73
89
  * Optional per-dataset processing memory: skip a dataset whose source
74
90
  * fingerprint and {@link pipelineVersion} both match the stored record.
@@ -1 +1 @@
1
- {"version":3,"file":"search-indexer-pipeline.d.ts","sourceRoot":"","sources":["../src/search-indexer-pipeline.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAEL,QAAQ,EACR,KAAK,eAAe,EACpB,KAAK,oBAAoB,EACzB,KAAK,gBAAgB,EACrB,KAAK,eAAe,EACpB,KAAK,aAAa,EAClB,KAAK,aAAa,EAClB,KAAK,MAAM,EACZ,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAO1E,OAAO,KAAK,EAAE,mBAAmB,EA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;;;;;;;;;;;;;;;;GAoCG;AACH,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,4BAA4B,GACpC,QAAQ,CAAC,mBAAmB,CAAC,CAsC/B"}
@@ -39,9 +39,10 @@ import { registrySource, searchStages, selectByClass, } from './search-stages.js
39
39
  * those, this convenience owns no capability of its own.
40
40
  */
41
41
  export function searchIndexerPipeline(options) {
42
- const { schema, datasets, registryTypes, transforms } = options;
42
+ const { schema, datasets, registryTypes, transforms, restrictRoots = {}, } = options;
43
43
  const fromRegistry = registryTypeNames(schema, registryTypes?.names);
44
44
  assertDeclaredTypeNames(schema, Object.keys(transforms ?? {}), 'transform');
45
+ assertRestrictable(schema, restrictRoots, fromRegistry);
45
46
  const sourceFor = registryTypes === undefined
46
47
  ? undefined
47
48
  : registrySource(registryTypes.endpoint);
@@ -55,14 +56,14 @@ export function searchIndexerPipeline(options) {
55
56
  types: [...schema.values()].map((searchType) => ({
56
57
  searchType,
57
58
  rootVariable: 'root',
58
- itemSelector: selectByClass(searchType),
59
+ itemSelector: rootSelector(searchType, restrictRoots),
59
60
  sourceFor: fromRegistry.has(searchType.name) ? sourceFor : undefined,
60
61
  transform: transforms?.[searchType.name],
61
62
  })),
62
63
  }),
63
64
  writers: searchIndexWriter({ schema, writerFor: options.writerFor }),
64
65
  provenanceStore: options.provenanceStore,
65
- pipelineVersion: options.pipelineVersion,
66
+ pipelineVersion: versionWithRestrictions(options.pipelineVersion, restrictRoots),
66
67
  reporter: options.reporter,
67
68
  });
68
69
  }
@@ -94,3 +95,46 @@ function assertDeclaredTypeNames(schema, names, label) {
94
95
  .join(', ')}.`);
95
96
  }
96
97
  }
98
+ /**
99
+ * Validate {@link SearchIndexerPipelineOptions.restrictRoots} at wiring time: a
100
+ * misspelt name would otherwise restrict nothing and index every root, and a
101
+ * registry-sourced type would apply a pattern meant for the records to the
102
+ * dataset’s description.
103
+ */
104
+ function assertRestrictable(schema, restrictRoots, fromRegistry) {
105
+ const names = Object.keys(restrictRoots);
106
+ assertDeclaredTypeNames(schema, names, 'restricted root');
107
+ const fromRegistryNames = names.filter((name) => fromRegistry.has(name));
108
+ if (fromRegistryNames.length > 0) {
109
+ throw new Error(`restrictRoots cannot restrict ${fromRegistryNames
110
+ .map((name) => `“${name}”`)
111
+ .join(', ')}: registry-sourced types describe the dataset, not its records.`);
112
+ }
113
+ }
114
+ /**
115
+ * The pipeline version a provenance skip is keyed by: the consumer’s, extended
116
+ * with the restrictions, so changing one re-indexes every dataset instead of
117
+ * skipping it with its old selection.
118
+ */
119
+ function versionWithRestrictions(pipelineVersion, restrictRoots) {
120
+ return pipelineVersion === undefined ||
121
+ Object.keys(restrictRoots).length === 0
122
+ ? pipelineVersion
123
+ : `${pipelineVersion}+restrictRoots=${JSON.stringify(restrictRoots)}`;
124
+ }
125
+ /** The type’s {@link selectByClass} selector, restricted by its
126
+ * {@link SearchIndexerPipelineOptions.restrictRoots} pattern if it has one. */
127
+ function rootSelector(searchType, restrictRoots) {
128
+ // Own keys only: a type named after an `Object.prototype` member must not
129
+ // pick up the inherited function as its pattern.
130
+ if (!Object.hasOwn(restrictRoots, searchType.name)) {
131
+ return selectByClass(searchType);
132
+ }
133
+ try {
134
+ return selectByClass(searchType, 'root', restrictRoots[searchType.name]);
135
+ }
136
+ catch (cause) {
137
+ // selectByClass and the SPARQL parser throw an Error saying what is wrong.
138
+ throw new Error(`restrictRoots for “${searchType.name}” is not a usable SPARQL graph pattern: ${cause.message}`, { cause });
139
+ }
140
+ }
@@ -117,8 +117,23 @@ export declare function searchStages(options: SearchStagesOptions): Stage<TypedS
117
117
  * `rootVariable` defaults to `root` and must match the stage’s
118
118
  * {@link SearchStageType.rootVariable}; it must not be `dataset` (reserved by the
119
119
  * SPARQL reader).
120
+ *
121
+ * `pattern`, a SPARQL graph pattern over `?‹rootVariable›`, restricts the
122
+ * selection to the instances that also match it, e.g.
123
+ * `?root <https://schema.org/about> <http://vocab.getty.edu/aat/300000000>`.
124
+ * The reader injects the selected roots into the extraction, so a root the
125
+ * pattern leaves out is never extracted, projected or written. The query
126
+ * declares no prefixes, so write IRIs in full.
127
+ *
128
+ * The pattern is its own group, so a `UNION` of complete groups or a trailing
129
+ * comment stays under the class constraint and the blank-node filter. The
130
+ * pattern is spliced in as text, though: one with unbalanced braces can close
131
+ * the group itself. It must mention `?‹rootVariable›` – one over another
132
+ * variable joins nothing to the root, so it would restrict nothing – and that
133
+ * is checked by name only, so a mention inside `OPTIONAL` or a comment passes.
134
+ * A pattern without the variable, or one that does not parse, throws here.
120
135
  */
121
- export declare function selectByClass(searchType: RootType, rootVariable?: string): ItemSelector;
136
+ export declare function selectByClass(searchType: RootType, rootVariable?: string, pattern?: string): ItemSelector;
122
137
  /**
123
138
  * A {@link SearchStageType.sourceFor} that reads a root type from the **dataset
124
139
  * registry** instead of from the dataset’s own data – the endpoint fixed,
@@ -1 +1 @@
1
- {"version":3,"file":"search-stages.d.ts","sourceRoot":"","sources":["../src/search-stages.ts"],"names":[],"mappings":"AACA,OAAO,EAGL,KAAK,EAEL,KAAK,YAAY,EACjB,KAAK,aAAa,EAClB,KAAK,aAAa,EAClB,KAAK,YAAY,EACjB,KAAK,YAAY,EAClB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAgB,KAAK,QAAQ,EAAE,KAAK,YAAY,EAAE,MAAM,aAAa,CAAC;AAE7E,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAEtE,kDAAkD;AAClD,MAAM,WAAW,eAAe;IAC9B;;;;;;OAMG;IACH,UAAU,EAAE,QAAQ,CAAC;IACrB;;;;;OAKG;IACH,YAAY,EAAE,MAAM,CAAC;IACrB;;;;OAIG;IACH,YAAY,EAAE,YAAY,CAAC;IAC3B;;;;;;;;OAQG;IACH,OAAO,CAAC,EAAE,YAAY,CAAC;IACvB;;;;;;;;;;;;;;;OAeG;IACH,SAAS,CAAC,EAAE,aAAa,CAAC,aAAa,CAAC,GAAG,aAAa,CAAC,aAAa,CAAC,EAAE,CAAC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;IACrB;;;;;OAKG;IACH,YAAY,EAAE,MAAM,CAAC;IACrB;;;;OAIG;IACH,YAAY,EAAE,YAAY,CAAC;IAC3B;;;;;;;;OAQG;IACH,OAAO,CAAC,EAAE,YAAY,CAAC;IACvB;;;;;;;;;;;;;;;OAeG;IACH,SAAS,CAAC,EAAE,aAAa,CAAC,aAAa,CAAC,GAAG,aAAa,CAAC,aAAa,CAAC,EAAE,CAAC;IAC1E;;;;;OAKG;IACH,SAAS,CAAC,EAAE,YAAY,CAAC,mBAAmB,CAAC,CAAC,WAAW,CAAC,CAAC;IAC3D;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,8EAA8E;IAC9E,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB;;;;OAIG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,wCAAwC;AACxC,MAAM,WAAW,mBAAmB;IAClC;;;OAGG;IACH,MAAM,EAAE,YAAY,CAAC;IACrB,4DAA4D;IAC5D,KAAK,EAAE,SAAS,eAAe,EAAE,CAAC;CACnC;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,YAAY,CAC1B,OAAO,EAAE,mBAAmB,GAC3B,KAAK,CAAC,mBAAmB,CAAC,EAAE,CAkF9B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,wBAAgB,aAAa,CAC3B,UAAU,EAAE,QAAQ,EACpB,YAAY,SAAS,EACrB,OAAO,CAAC,EAAE,MAAM,GACf,YAAY,CAWd;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AACH,wBAAgB,cAAc,CAC5B,QAAQ,EAAE,GAAG,GACZ,WAAW,CAAC,eAAe,CAAC,WAAW,CAAC,CAAC,CAK3C"}
@@ -75,7 +75,11 @@ export function searchStages(options) {
75
75
  // The same `iri.toString()` the writer’s provenance bookkeeping and
76
76
  // `selectedSources()` use, so a declared field, the membership sweep
77
77
  // and the selection all compare one spelling of the IRI.
78
- { dataset: context.dataset.iri.toString() })) {
78
+ {
79
+ dataset: context.dataset.iri.toString(),
80
+ // Tallied by the pipeline and reported when the dataset completes.
81
+ onUnreadable: ({ field, id, value }) => context.valueUnread(searchType.name, field, { id, value }),
82
+ })) {
79
83
  yield { searchType, document };
80
84
  }
81
85
  },
@@ -101,10 +105,30 @@ export function searchStages(options) {
101
105
  * `rootVariable` defaults to `root` and must match the stage’s
102
106
  * {@link SearchStageType.rootVariable}; it must not be `dataset` (reserved by the
103
107
  * SPARQL reader).
108
+ *
109
+ * `pattern`, a SPARQL graph pattern over `?‹rootVariable›`, restricts the
110
+ * selection to the instances that also match it, e.g.
111
+ * `?root <https://schema.org/about> <http://vocab.getty.edu/aat/300000000>`.
112
+ * The reader injects the selected roots into the extraction, so a root the
113
+ * pattern leaves out is never extracted, projected or written. The query
114
+ * declares no prefixes, so write IRIs in full.
115
+ *
116
+ * The pattern is its own group, so a `UNION` of complete groups or a trailing
117
+ * comment stays under the class constraint and the blank-node filter. The
118
+ * pattern is spliced in as text, though: one with unbalanced braces can close
119
+ * the group itself. It must mention `?‹rootVariable›` – one over another
120
+ * variable joins nothing to the root, so it would restrict nothing – and that
121
+ * is checked by name only, so a mention inside `OPTIONAL` or a comment passes.
122
+ * A pattern without the variable, or one that does not parse, throws here.
104
123
  */
105
- export function selectByClass(searchType, rootVariable = 'root') {
124
+ export function selectByClass(searchType, rootVariable = 'root', pattern) {
125
+ if (pattern !== undefined &&
126
+ !new RegExp(`[?$]${rootVariable}\\b`).test(pattern)) {
127
+ throw new Error(`The pattern must constrain ?${rootVariable}.`);
128
+ }
129
+ const restriction = pattern === undefined ? '' : `{\n${pattern}\n}`;
106
130
  return new SparqlItemSelector({
107
- query: `SELECT DISTINCT ?${rootVariable} WHERE { ?${rootVariable} a <${searchType.class}> FILTER(!isBlank(?${rootVariable})) }`,
131
+ query: `SELECT DISTINCT ?${rootVariable} WHERE { ?${rootVariable} a <${searchType.class}> . ${restriction} FILTER(!isBlank(?${rootVariable})) }`,
108
132
  });
109
133
  }
110
134
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lde/search-pipeline",
3
- "version": "0.41.3",
3
+ "version": "0.43.0",
4
4
  "description": "Search indexing as an @lde/pipeline instance: a Writer<Quad> that applies the @lde/search projection to extracted RDF and fans each document out to the transactional engine writer for its type's collection. Glue between the pipeline quad world and the search-engine document world; owns no projection or engine logic itself.",
5
5
  "repository": {
6
6
  "url": "git+https://github.com/ldelements/lde.git",
@@ -25,14 +25,14 @@
25
25
  "!**/*.tsbuildinfo"
26
26
  ],
27
27
  "dependencies": {
28
- "@lde/search": "^0.36.4",
28
+ "@lde/search": "^0.38.0",
29
29
  "@traqula/generator-sparql-1-1": "^1.3.1",
30
30
  "@traqula/parser-sparql-1-1": "^1.3.1",
31
31
  "@traqula/rules-sparql-1-1": "^1.2.0",
32
32
  "tslib": "^2.3.0"
33
33
  },
34
34
  "devDependencies": {
35
- "@lde/search-typesense": "^0.44.2",
35
+ "@lde/search-typesense": "^0.46.0",
36
36
  "@rdfjs/types": "^2.0.1",
37
37
  "n3": "^2.13.12",
38
38
  "testcontainers": "^12.1.0",
@@ -40,6 +40,6 @@
40
40
  },
41
41
  "peerDependencies": {
42
42
  "@lde/dataset": "^0.10.1",
43
- "@lde/pipeline": "^0.42.1"
43
+ "@lde/pipeline": "^0.43.0"
44
44
  }
45
45
  }