@lde/search-pipeline 0.58.0 → 0.59.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.
- package/dist/extraction.d.ts +12 -1
- package/dist/extraction.d.ts.map +1 -1
- package/dist/extraction.js +18 -13
- package/dist/search-indexer-pipeline.d.ts +3 -0
- package/dist/search-indexer-pipeline.d.ts.map +1 -1
- package/dist/search-stages.d.ts +23 -1
- package/dist/search-stages.d.ts.map +1 -1
- package/dist/search-stages.js +139 -4
- package/package.json +5 -5
package/dist/extraction.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type QueryConstruct } from '@traqula/rules-sparql-1-1';
|
|
2
|
-
import type { SearchSchema, SearchType } from '@lde/search';
|
|
2
|
+
import type { RootType, SearchField, SearchSchema, SearchType } from '@lde/search';
|
|
3
3
|
/** Options for {@link extractionQuery}. */
|
|
4
4
|
export interface ExtractionOptions {
|
|
5
5
|
/**
|
|
@@ -67,4 +67,15 @@ export interface ExtractionOptions {
|
|
|
67
67
|
export declare function extractionQuery(searchType: SearchType, schema: SearchSchema, options?: ExtractionOptions): QueryConstruct;
|
|
68
68
|
/** {@link extractionQuery}, serialised to a SPARQL string a reader can run. */
|
|
69
69
|
export declare function extractionQueryString(searchType: SearchType, schema: SearchSchema, options?: ExtractionOptions): string;
|
|
70
|
+
/**
|
|
71
|
+
* The fields a reference reads off a referent of a target it does not expand
|
|
72
|
+
* `local`ly: the target’s key field, where it is keyed, and – for a
|
|
73
|
+
* `searchable` reference – its label field, by which the reference is searched.
|
|
74
|
+
*/
|
|
75
|
+
export declare function referentHopFields(field: SearchField, target: RootType): PathField[];
|
|
76
|
+
/** A field the extraction reads off a referent: path-bearing. */
|
|
77
|
+
type PathField = SearchField & {
|
|
78
|
+
readonly path: string;
|
|
79
|
+
};
|
|
80
|
+
export {};
|
|
70
81
|
//# sourceMappingURL=extraction.d.ts.map
|
package/dist/extraction.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extraction.d.ts","sourceRoot":"","sources":["../src/extraction.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,KAAK,cAAc,EAKpB,MAAM,2BAA2B,CAAC;AAanC,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"extraction.d.ts","sourceRoot":"","sources":["../src/extraction.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,KAAK,cAAc,EAKpB,MAAM,2BAA2B,CAAC;AAanC,OAAO,KAAK,EACV,QAAQ,EACR,WAAW,EACX,YAAY,EACZ,UAAU,EACX,MAAM,aAAa,CAAC;AAQrB,2CAA2C;AAC3C,MAAM,WAAW,iBAAiB;IAChC;;;;;;;OAOG;IACH,QAAQ,CAAC,eAAe,CAAC,EAAE,MAAM,CAAC;CACnC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmDG;AACH,wBAAgB,eAAe,CAC7B,UAAU,EAAE,UAAU,EACtB,MAAM,EAAE,YAAY,EACpB,OAAO,GAAE,iBAAsB,GAC9B,cAAc,CA2BhB;AAED,+EAA+E;AAC/E,wBAAgB,qBAAqB,CACnC,UAAU,EAAE,UAAU,EACtB,MAAM,EAAE,YAAY,EACpB,OAAO,CAAC,EAAE,iBAAiB,GAC1B,MAAM,CAER;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,WAAW,EAClB,MAAM,EAAE,QAAQ,GACf,SAAS,EAAE,CAQb;AA+XD,iEAAiE;AACjE,KAAK,SAAS,GAAG,WAAW,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC"}
|
package/dist/extraction.js
CHANGED
|
@@ -75,6 +75,20 @@ export function extractionQuery(searchType, schema, options = {}) {
|
|
|
75
75
|
export function extractionQueryString(searchType, schema, options) {
|
|
76
76
|
return generator.generate(extractionQuery(searchType, schema, options));
|
|
77
77
|
}
|
|
78
|
+
/**
|
|
79
|
+
* The fields a reference reads off a referent of a target it does not expand
|
|
80
|
+
* `local`ly: the target’s key field, where it is keyed, and – for a
|
|
81
|
+
* `searchable` reference – its label field, by which the reference is searched.
|
|
82
|
+
*/
|
|
83
|
+
export function referentHopFields(field, target) {
|
|
84
|
+
return [
|
|
85
|
+
keyedFieldOf(target),
|
|
86
|
+
// `searchSchema` guarantees a searchable reference’s label a path.
|
|
87
|
+
field.searchable === undefined
|
|
88
|
+
? undefined
|
|
89
|
+
: labelFieldOf(target),
|
|
90
|
+
].filter((hopField) => hopField !== undefined);
|
|
91
|
+
}
|
|
78
92
|
/**
|
|
79
93
|
* Walk a type’s path-bearing fields off a subject variable, collecting the
|
|
80
94
|
* template triples (minted aliases) and one WHERE branch per field (source
|
|
@@ -295,19 +309,10 @@ function buildReferentHops(field, referent, schema, counter, onPath) {
|
|
|
295
309
|
// is one of them, so emitting the hop as well would state it twice.
|
|
296
310
|
// A searchable reference is searched by its referents’ labels, so it
|
|
297
311
|
// reads them off the referent beside the key.
|
|
298
|
-
const
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
? undefined
|
|
303
|
-
: labelFieldOf(target),
|
|
304
|
-
];
|
|
305
|
-
for (const hopField of hopFields) {
|
|
306
|
-
if (hopField !== undefined) {
|
|
307
|
-
const built = buildFieldHop(target, hopField, referent, counter);
|
|
308
|
-
template.push(built.triple);
|
|
309
|
-
expansions.push(built.pattern);
|
|
310
|
-
}
|
|
312
|
+
for (const hopField of referentHopFields(field, target)) {
|
|
313
|
+
const built = buildFieldHop(target, hopField, referent, counter);
|
|
314
|
+
template.push(built.triple);
|
|
315
|
+
expansions.push(built.pattern);
|
|
311
316
|
}
|
|
312
317
|
continue;
|
|
313
318
|
}
|
|
@@ -86,6 +86,9 @@ export interface SearchIndexerPipelineOptions {
|
|
|
86
86
|
* Named by `name` rather than by class IRI, like {@link registryTypes}; a
|
|
87
87
|
* name the schema does not declare throws at wiring time rather than
|
|
88
88
|
* attaching nothing and shipping an unenriched collection.
|
|
89
|
+
*
|
|
90
|
+
* A type’s transforms also run on its referents in the stages of the types
|
|
91
|
+
* searching it by its labels ({@link SearchStageType.transform}).
|
|
89
92
|
*/
|
|
90
93
|
transforms?: Readonly<Record<string, QuadTransform<ReaderContext> | QuadTransform<ReaderContext>[]>>;
|
|
91
94
|
/**
|
|
@@ -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,EAEzB,KAAK,QAAQ,EACb,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;AAS1E,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAEtE;;;;GAIG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;;;;;;OAOG;IACH,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B;gEAC4D;IAC5D,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC;CAClC;AAED,iDAAiD;AACjD,MAAM,WAAW,4BAA4B;IAC3C;;;;OAIG;IACH,MAAM,EAAE,YAAY,CAAC;IACrB;;;;OAIG;IACH,QAAQ,EAAE,OAAO,EAAE,GAAG,eAAe,CAAC;IACtC;;;;;;;;OAQG;IACH,oBAAoB,CAAC,EAAE,oBAAoB,CAAC;IAC5C;;;;;;;OAOG;IACH,SAAS,EAAE,CACT,UAAU,EAAE,QAAQ,EACpB,MAAM,EAAE,YAAY,KACjB,MAAM,CAAC,cAAc,CAAC,CAAC;IAC5B;;;;;;;;;;;;OAYG;IACH,aAAa,CAAC,EAAE;QACd,+DAA+D;QAC/D,QAAQ,EAAE,GAAG,CAAC;QACd,oEAAoE;QACpE,KAAK,EAAE,SAAS,MAAM,EAAE,CAAC;KAC1B,CAAC;IACF
|
|
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,EAEzB,KAAK,QAAQ,EACb,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;AAS1E,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAEtE;;;;GAIG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;;;;;;OAOG;IACH,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B;gEAC4D;IAC5D,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC;CAClC;AAED,iDAAiD;AACjD,MAAM,WAAW,4BAA4B;IAC3C;;;;OAIG;IACH,MAAM,EAAE,YAAY,CAAC;IACrB;;;;OAIG;IACH,QAAQ,EAAE,OAAO,EAAE,GAAG,eAAe,CAAC;IACtC;;;;;;;;OAQG;IACH,oBAAoB,CAAC,EAAE,oBAAoB,CAAC;IAC5C;;;;;;;OAOG;IACH,SAAS,EAAE,CACT,UAAU,EAAE,QAAQ,EACpB,MAAM,EAAE,YAAY,KACjB,MAAM,CAAC,cAAc,CAAC,CAAC;IAC5B;;;;;;;;;;;;OAYG;IACH,aAAa,CAAC,EAAE;QACd,+DAA+D;QAC/D,QAAQ,EAAE,GAAG,CAAC;QACd,oEAAoE;QACpE,KAAK,EAAE,SAAS,MAAM,EAAE,CAAC;KAC1B,CAAC;IACF;;;;;;;;;;;;;;;;OAgBG;IACH,UAAU,CAAC,EAAE,QAAQ,CACnB,MAAM,CACJ,MAAM,EACN,aAAa,CAAC,aAAa,CAAC,GAAG,aAAa,CAAC,aAAa,CAAC,EAAE,CAC9D,CACF,CAAC;IACF;;;;;;;;;;;;;;OAcG;IACH,aAAa,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IACjD;;;OAGG;IACH,MAAM,CAAC,EAAE,gBAAgB,CAAC;IAC1B;;;;OAIG;IACH,YAAY,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC,CAAC;IAC1D;;;;OAIG;IACH,eAAe,CAAC,EAAE,eAAe,CAAC;IAClC;;;;OAIG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB;;;OAGG;IACH,QAAQ,CAAC,EAAE,QAAQ,GAAG,SAAS,QAAQ,EAAE,CAAC;CAC3C;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AACH,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,4BAA4B,GACpC,QAAQ,CAAC,mBAAmB,CAAC,CA0C/B"}
|
package/dist/search-stages.d.ts
CHANGED
|
@@ -49,6 +49,15 @@ export interface SearchStageType {
|
|
|
49
49
|
* A field a transform fills must still declare a `path`: projection skips a
|
|
50
50
|
* field with neither a `path` nor a `derive`, so a transform-minted IR Alias
|
|
51
51
|
* is otherwise never read.
|
|
52
|
+
*
|
|
53
|
+
* **It also runs on this type’s referents in other stages.** Where another
|
|
54
|
+
* type’s `searchable` reference names this type as its target, that stage
|
|
55
|
+
* hands the transform(s) each referent its batch read – the referent’s key
|
|
56
|
+
* and label field under this type’s IR Aliases, and nothing else – so the
|
|
57
|
+
* reference is searched by the labels this type’s documents get. A transform
|
|
58
|
+
* must therefore cope with a node carrying only those two fields, once per
|
|
59
|
+
* referring batch. A reference from this type to itself gets no separate
|
|
60
|
+
* pass: this transform already sees its referents’ quads in the batch.
|
|
52
61
|
*/
|
|
53
62
|
transform?: QuadTransform<ReaderContext> | QuadTransform<ReaderContext>[];
|
|
54
63
|
/**
|
|
@@ -106,6 +115,12 @@ export interface SearchStagesOptions {
|
|
|
106
115
|
* projection as `ProjectionContext.datasetDocument`, so a `derive` can copy a
|
|
107
116
|
* field of the dataset onto each document.
|
|
108
117
|
*
|
|
118
|
+
* Before projection, a stage passes the referents of its `searchable`
|
|
119
|
+
* references through their target type’s
|
|
120
|
+
* {@link SearchStageType.transform transform(s)}, so a reference is searched
|
|
121
|
+
* by the labels the target’s documents get. A stage with its own `readers`
|
|
122
|
+
* gets no such pass.
|
|
123
|
+
*
|
|
109
124
|
* Wire the result as `new Pipeline<TypedSearchDocument>({ datasetSelector,
|
|
110
125
|
* stages: searchStages(...), writers: searchIndexWriter(...) })` – one terminal,
|
|
111
126
|
* N stages.
|
|
@@ -114,7 +129,7 @@ export declare function searchStages(options: SearchStagesOptions): Stage<TypedS
|
|
|
114
129
|
/**
|
|
115
130
|
* An {@link ItemSelector} that selects every instance of a root type’s source
|
|
116
131
|
* class:
|
|
117
|
-
* `SELECT DISTINCT ?‹rootVariable› WHERE { ?‹rootVariable› a <class> FILTER(!isBlank(?‹rootVariable›)) }
|
|
132
|
+
* `SELECT DISTINCT ?‹rootVariable› WHERE { ?‹rootVariable› a <class> FILTER(!isBlank(?‹rootVariable›)) } ORDER BY ?‹rootVariable›`.
|
|
118
133
|
* A convenience for the **object grain**, where {@link RootType.class} really is
|
|
119
134
|
* the source class – **not** a default: root selection is a deployment concern,
|
|
120
135
|
* and three of the Dataset Register’s four catalog types have no source class at
|
|
@@ -127,6 +142,13 @@ export declare function searchStages(options: SearchStagesOptions): Stage<TypedS
|
|
|
127
142
|
* full, so pagination walks the whole class instead of stopping at the first
|
|
128
143
|
* page a client-side drop would leave short.
|
|
129
144
|
*
|
|
145
|
+
* **The roots are ordered** (`ORDER BY ?‹rootVariable›`): the selector pages with
|
|
146
|
+
* `LIMIT`/`OFFSET`, and without a total order an endpoint may answer each page
|
|
147
|
+
* in a different order, skipping or repeating roots between pages. The order
|
|
148
|
+
* holds the pages together only while the data does not change during the
|
|
149
|
+
* selection: a root added or removed before the current offset shifts every
|
|
150
|
+
* later page by one.
|
|
151
|
+
*
|
|
130
152
|
* `rootVariable` defaults to `root` and must match the stage’s
|
|
131
153
|
* {@link SearchStageType.rootVariable}; it must not be `dataset` (reserved by the
|
|
132
154
|
* SPARQL reader).
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"search-stages.d.ts","sourceRoot":"","sources":["../src/search-stages.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"search-stages.d.ts","sourceRoot":"","sources":["../src/search-stages.ts"],"names":[],"mappings":"AAEA,OAAO,EAGL,KAAK,EAEL,KAAK,YAAY,EACjB,KAAK,aAAa,EAClB,KAAK,aAAa,EAClB,KAAK,YAAY,EACjB,KAAK,YAAY,EAClB,MAAM,eAAe,CAAC;AACvB,OAAO,EAGL,KAAK,QAAQ,EAGb,KAAK,YAAY,EAElB,MAAM,aAAa,CAAC;AASrB,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;;;;;;;;;;;;;;;;;;;;;;;;OAwBG;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;;;;;;;;;;;OAWG;IACH,SAAS,CAAC,EAAE,YAAY,CAAC,mBAAmB,CAAC,CAAC,WAAW,CAAC,CAAC;IAC3D,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;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,YAAY,CAC1B,OAAO,EAAE,mBAAmB,GAC3B,KAAK,CAAC,mBAAmB,CAAC,EAAE,CAyH9B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;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;AAED,iEAAiE;AACjE,eAAO,MAAM,gBAAgB;;;CAA2C,CAAC"}
|
package/dist/search-stages.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { Distribution } from '@lde/dataset';
|
|
2
2
|
import { SparqlConstructReader, SparqlItemSelector, Stage, } from '@lde/pipeline';
|
|
3
3
|
import { projectRoots, } from '@lde/search';
|
|
4
|
-
import {
|
|
4
|
+
import { endpointFieldOf, irAlias, isInlineReference, referencedTargetsOf, referenceTypeNamed, } from '@lde/search/adapter';
|
|
5
|
+
import { extractionQueryString, referentHopFields } from './extraction.js';
|
|
5
6
|
/**
|
|
6
7
|
* Compose one projecting {@link Stage} per root type – the source side of a
|
|
7
8
|
* search pipeline. Each stage selects its own roots, extracts each root’s quads,
|
|
@@ -18,6 +19,12 @@ import { extractionQueryString } from './extraction.js';
|
|
|
18
19
|
* projection as `ProjectionContext.datasetDocument`, so a `derive` can copy a
|
|
19
20
|
* field of the dataset onto each document.
|
|
20
21
|
*
|
|
22
|
+
* Before projection, a stage passes the referents of its `searchable`
|
|
23
|
+
* references through their target type’s
|
|
24
|
+
* {@link SearchStageType.transform transform(s)}, so a reference is searched
|
|
25
|
+
* by the labels the target’s documents get. A stage with its own `readers`
|
|
26
|
+
* gets no such pass.
|
|
27
|
+
*
|
|
21
28
|
* Wire the result as `new Pipeline<TypedSearchDocument>({ datasetSelector,
|
|
22
29
|
* stages: searchStages(...), writers: searchIndexWriter(...) })` – one terminal,
|
|
23
30
|
* N stages.
|
|
@@ -37,6 +44,13 @@ export function searchStages(options) {
|
|
|
37
44
|
...types.filter(isDatasetType),
|
|
38
45
|
...types.filter((type) => !isDatasetType(type)),
|
|
39
46
|
];
|
|
47
|
+
// Each type’s transforms, for the referring stages to apply to its
|
|
48
|
+
// referents. A type with its own readers has none here: `transform`
|
|
49
|
+
// attaches to the default reader only.
|
|
50
|
+
const transformsByClass = new Map(types.flatMap((type) => type.transform === undefined
|
|
51
|
+
? []
|
|
52
|
+
: // By class, as the schema resolves a class-equal lookalike.
|
|
53
|
+
[[type.searchType.class, [type.transform].flat()]]));
|
|
40
54
|
return ordered.map((type) => {
|
|
41
55
|
// Project with the schema’s OWN declaration object, whatever the caller
|
|
42
56
|
// passed: `assertTypeInSchema` (inside `projectRoots`) is an identity check,
|
|
@@ -64,7 +78,10 @@ export function searchStages(options) {
|
|
|
64
78
|
subjectVariable: rootVariable,
|
|
65
79
|
}),
|
|
66
80
|
}),
|
|
67
|
-
transform:
|
|
81
|
+
transform: [
|
|
82
|
+
type.transform ?? [],
|
|
83
|
+
referentTransforms(searchType, schema, transformsByClass) ?? [],
|
|
84
|
+
].flat(),
|
|
68
85
|
};
|
|
69
86
|
return new Stage({
|
|
70
87
|
name: searchType.name,
|
|
@@ -117,7 +134,7 @@ export function searchStages(options) {
|
|
|
117
134
|
/**
|
|
118
135
|
* An {@link ItemSelector} that selects every instance of a root type’s source
|
|
119
136
|
* class:
|
|
120
|
-
* `SELECT DISTINCT ?‹rootVariable› WHERE { ?‹rootVariable› a <class> FILTER(!isBlank(?‹rootVariable›)) }
|
|
137
|
+
* `SELECT DISTINCT ?‹rootVariable› WHERE { ?‹rootVariable› a <class> FILTER(!isBlank(?‹rootVariable›)) } ORDER BY ?‹rootVariable›`.
|
|
121
138
|
* A convenience for the **object grain**, where {@link RootType.class} really is
|
|
122
139
|
* the source class – **not** a default: root selection is a deployment concern,
|
|
123
140
|
* and three of the Dataset Register’s four catalog types have no source class at
|
|
@@ -130,6 +147,13 @@ export function searchStages(options) {
|
|
|
130
147
|
* full, so pagination walks the whole class instead of stopping at the first
|
|
131
148
|
* page a client-side drop would leave short.
|
|
132
149
|
*
|
|
150
|
+
* **The roots are ordered** (`ORDER BY ?‹rootVariable›`): the selector pages with
|
|
151
|
+
* `LIMIT`/`OFFSET`, and without a total order an endpoint may answer each page
|
|
152
|
+
* in a different order, skipping or repeating roots between pages. The order
|
|
153
|
+
* holds the pages together only while the data does not change during the
|
|
154
|
+
* selection: a root added or removed before the current offset shifts every
|
|
155
|
+
* later page by one.
|
|
156
|
+
*
|
|
133
157
|
* `rootVariable` defaults to `root` and must match the stage’s
|
|
134
158
|
* {@link SearchStageType.rootVariable}; it must not be `dataset` (reserved by the
|
|
135
159
|
* SPARQL reader).
|
|
@@ -156,7 +180,7 @@ export function selectByClass(searchType, rootVariable = 'root', pattern) {
|
|
|
156
180
|
}
|
|
157
181
|
const restriction = pattern === undefined ? '' : `{\n${pattern}\n}`;
|
|
158
182
|
return new SparqlItemSelector({
|
|
159
|
-
query: `SELECT DISTINCT ?${rootVariable} WHERE { ?${rootVariable} a <${searchType.class}> . ${restriction} FILTER(!isBlank(?${rootVariable})) }`,
|
|
183
|
+
query: `SELECT DISTINCT ?${rootVariable} WHERE { ?${rootVariable} a <${searchType.class}> . ${restriction} FILTER(!isBlank(?${rootVariable})) } ORDER BY ?${rootVariable}`,
|
|
160
184
|
});
|
|
161
185
|
}
|
|
162
186
|
/**
|
|
@@ -210,5 +234,116 @@ export function registrySource(endpoint) {
|
|
|
210
234
|
}
|
|
211
235
|
/** {@link SearchStageType.batchSize} when the type sets none. */
|
|
212
236
|
export const defaultBatchSize = { endpoint: 10, imported: 100 };
|
|
237
|
+
/**
|
|
238
|
+
* A transform passing each referent of the type’s `searchable` references,
|
|
239
|
+
* its inline referents’ included, through its target type’s transforms: the
|
|
240
|
+
* quads the extraction read off the referent ({@link referentHopFields}) go
|
|
241
|
+
* in, and what the target’s transforms make of them comes back in their place.
|
|
242
|
+
* `undefined` where no such reference names a target with transforms.
|
|
243
|
+
*
|
|
244
|
+
* The batch is buffered to find the referents, so memory stays bounded by the
|
|
245
|
+
* stage’s `batchSize`.
|
|
246
|
+
*/
|
|
247
|
+
function referentTransforms(searchType, schema, transformsByClass) {
|
|
248
|
+
// Per target with transforms: the reference fields naming it, and the
|
|
249
|
+
// aliases its referents carry. A target’s aliases are its own, so no quad
|
|
250
|
+
// belongs to two targets.
|
|
251
|
+
const routes = new Map();
|
|
252
|
+
for (const { alias, field } of searchedReferences(searchType, schema)) {
|
|
253
|
+
for (const target of referencedTargetsOf(field, schema)) {
|
|
254
|
+
// A reference to its own type: the type’s transform saw the batch.
|
|
255
|
+
if (target !== searchType &&
|
|
256
|
+
transformsByClass.get(target.class) !== undefined) {
|
|
257
|
+
const route = routes.get(target) ?? {
|
|
258
|
+
fields: new Set(),
|
|
259
|
+
aliases: new Set(),
|
|
260
|
+
};
|
|
261
|
+
route.fields.add(alias);
|
|
262
|
+
for (const hopField of referentHopFields(field, target)) {
|
|
263
|
+
route.aliases.add(irAlias(target, hopField));
|
|
264
|
+
}
|
|
265
|
+
routes.set(target, route);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
if (routes.size === 0) {
|
|
270
|
+
return undefined;
|
|
271
|
+
}
|
|
272
|
+
const targetsByField = new Map();
|
|
273
|
+
const targetByAlias = new Map();
|
|
274
|
+
for (const [target, { fields, aliases }] of routes) {
|
|
275
|
+
for (const field of fields) {
|
|
276
|
+
targetsByField.set(field, [...(targetsByField.get(field) ?? []), target]);
|
|
277
|
+
}
|
|
278
|
+
for (const alias of aliases) {
|
|
279
|
+
targetByAlias.set(alias, target);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
return async function* referentTransforms(quads, context) {
|
|
283
|
+
const batch = [];
|
|
284
|
+
// Each target’s referents in this batch: the objects of the references
|
|
285
|
+
// naming it.
|
|
286
|
+
const referents = new Map();
|
|
287
|
+
for await (const quad of quads) {
|
|
288
|
+
batch.push(quad);
|
|
289
|
+
for (const target of targetsByField.get(quad.predicate.value) ?? []) {
|
|
290
|
+
const keys = referents.get(target) ?? new Set();
|
|
291
|
+
keys.add(termKey(quad.object));
|
|
292
|
+
referents.set(target, keys);
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
// One pass sorting each quad into its target’s input, or keeping it.
|
|
296
|
+
const inputs = new Map();
|
|
297
|
+
for (const quad of batch) {
|
|
298
|
+
const target = targetByAlias.get(quad.predicate.value);
|
|
299
|
+
if (target !== undefined &&
|
|
300
|
+
referents.get(target)?.has(termKey(quad.subject))) {
|
|
301
|
+
const input = inputs.get(target) ?? [];
|
|
302
|
+
input.push(quad);
|
|
303
|
+
inputs.set(target, input);
|
|
304
|
+
}
|
|
305
|
+
else {
|
|
306
|
+
yield quad;
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
for (const [target, input] of inputs) {
|
|
310
|
+
let stream = streamOf(input);
|
|
311
|
+
for (const transform of transformsByClass.get(target.class)) {
|
|
312
|
+
stream = transform(stream, context);
|
|
313
|
+
}
|
|
314
|
+
yield* stream;
|
|
315
|
+
}
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
/** The type’s `searchable` reference fields, each with the IR Alias whose
|
|
319
|
+
* objects are its referents: its own, and those of the inline referents it
|
|
320
|
+
* nests. A graph that leaves an edge out points at the endpoint through the
|
|
321
|
+
* inline field itself, so an endpoint field is reached through both.
|
|
322
|
+
* `searchSchema` refuses an inline cycle, so the descent ends. */
|
|
323
|
+
function searchedReferences(owner, schema) {
|
|
324
|
+
return owner.fields.flatMap((field) => {
|
|
325
|
+
if (isInlineReference(field)) {
|
|
326
|
+
// Guaranteed declared: `searchSchema` resolves every inline `typeName`.
|
|
327
|
+
const referenceType = referenceTypeNamed(schema, field.ref.typeName);
|
|
328
|
+
const endpointField = endpointFieldOf(referenceType, field.ref.identity);
|
|
329
|
+
return [
|
|
330
|
+
...searchedReferences(referenceType, schema),
|
|
331
|
+
...(endpointField?.searchable === undefined
|
|
332
|
+
? []
|
|
333
|
+
: [{ alias: irAlias(owner, field), field: endpointField }]),
|
|
334
|
+
];
|
|
335
|
+
}
|
|
336
|
+
return field.kind === 'reference' && field.searchable !== undefined
|
|
337
|
+
? [{ alias: irAlias(owner, field), field }]
|
|
338
|
+
: [];
|
|
339
|
+
});
|
|
340
|
+
}
|
|
341
|
+
/** A term’s identity as a string: a blank node never equals an IRI. */
|
|
342
|
+
function termKey(term) {
|
|
343
|
+
return `${term.termType}:${term.value}`;
|
|
344
|
+
}
|
|
345
|
+
async function* streamOf(quads) {
|
|
346
|
+
yield* quads;
|
|
347
|
+
}
|
|
213
348
|
/** The class of a root type that describes the dataset being indexed. */
|
|
214
349
|
const DCAT_DATASET = 'http://www.w3.org/ns/dcat#Dataset';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lde/search-pipeline",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.59.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,21 +25,21 @@
|
|
|
25
25
|
"!**/*.tsbuildinfo"
|
|
26
26
|
],
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@lde/search": "^0.46.
|
|
28
|
+
"@lde/search": "^0.46.1",
|
|
29
|
+
"@rdfjs/types": "^2.0.1",
|
|
29
30
|
"@traqula/generator-sparql-1-1": "^1.3.1",
|
|
30
31
|
"@traqula/parser-sparql-1-1": "^1.3.1",
|
|
31
32
|
"@traqula/rules-sparql-1-1": "^1.2.0",
|
|
32
33
|
"tslib": "^2.3.0"
|
|
33
34
|
},
|
|
34
35
|
"devDependencies": {
|
|
35
|
-
"@lde/search-typesense": "^0.61.
|
|
36
|
-
"@rdfjs/types": "^2.0.1",
|
|
36
|
+
"@lde/search-typesense": "^0.61.2",
|
|
37
37
|
"n3": "^2.13.12",
|
|
38
38
|
"testcontainers": "^12.1.0",
|
|
39
39
|
"typesense": "^3.2.0"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
42
42
|
"@lde/dataset": "^0.10.1",
|
|
43
|
-
"@lde/pipeline": "^0.50.
|
|
43
|
+
"@lde/pipeline": "^0.50.3"
|
|
44
44
|
}
|
|
45
45
|
}
|