ochre-sdk 0.20.29 → 0.20.30
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/index.mjs +55 -3
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -2409,6 +2409,52 @@ function buildOrCtsQueryExpression(queries) {
|
|
|
2409
2409
|
if (queries.length === 1) return queries[0] ?? "cts:false-query()";
|
|
2410
2410
|
return `cts:or-query((${queries.join(", ")}))`;
|
|
2411
2411
|
}
|
|
2412
|
+
function buildPredicateGroups(predicateParts) {
|
|
2413
|
+
const groups = [];
|
|
2414
|
+
let currentGroup = [];
|
|
2415
|
+
for (const predicatePart of predicateParts) {
|
|
2416
|
+
if (predicatePart.operator == null || predicatePart.operator === "AND") {
|
|
2417
|
+
currentGroup.push(predicatePart.predicate);
|
|
2418
|
+
continue;
|
|
2419
|
+
}
|
|
2420
|
+
if (currentGroup.length > 0) groups.push(currentGroup);
|
|
2421
|
+
currentGroup = [predicatePart.predicate];
|
|
2422
|
+
}
|
|
2423
|
+
if (currentGroup.length > 0) groups.push(currentGroup);
|
|
2424
|
+
return groups;
|
|
2425
|
+
}
|
|
2426
|
+
function buildGroupedPredicateExpression(predicateGroups) {
|
|
2427
|
+
if (predicateGroups.length === 0) return "";
|
|
2428
|
+
const groupExpressions = [];
|
|
2429
|
+
for (let index = 0; index < predicateGroups.length;) {
|
|
2430
|
+
const predicateGroup = predicateGroups[index];
|
|
2431
|
+
const firstPredicate = predicateGroup?.[0];
|
|
2432
|
+
if (predicateGroup == null || predicateGroup.length < 2 || firstPredicate == null) {
|
|
2433
|
+
groupExpressions.push(buildAndPredicate(predicateGroup ?? []));
|
|
2434
|
+
index += 1;
|
|
2435
|
+
continue;
|
|
2436
|
+
}
|
|
2437
|
+
let sharedGroupEnd = index + 1;
|
|
2438
|
+
while (sharedGroupEnd < predicateGroups.length) {
|
|
2439
|
+
const sharedGroup = predicateGroups[sharedGroupEnd];
|
|
2440
|
+
if (sharedGroup == null || sharedGroup.length < 2 || sharedGroup[0] !== firstPredicate) break;
|
|
2441
|
+
sharedGroupEnd += 1;
|
|
2442
|
+
}
|
|
2443
|
+
if (sharedGroupEnd === index + 1) {
|
|
2444
|
+
groupExpressions.push(buildAndPredicate(predicateGroup));
|
|
2445
|
+
index += 1;
|
|
2446
|
+
continue;
|
|
2447
|
+
}
|
|
2448
|
+
const suffixGroupExpressions = [];
|
|
2449
|
+
for (const sharedGroup of predicateGroups.slice(index, sharedGroupEnd)) {
|
|
2450
|
+
const suffixPredicates = sharedGroup.slice(1);
|
|
2451
|
+
suffixGroupExpressions.push(buildAndPredicate(suffixPredicates));
|
|
2452
|
+
}
|
|
2453
|
+
groupExpressions.push(buildAndPredicate([firstPredicate, buildOrPredicate(suffixGroupExpressions)]));
|
|
2454
|
+
index = sharedGroupEnd;
|
|
2455
|
+
}
|
|
2456
|
+
return buildOrPredicate(groupExpressions);
|
|
2457
|
+
}
|
|
2412
2458
|
function buildContentTargetCandidateBranch(params) {
|
|
2413
2459
|
const { containerElementName, termExpression, isCaseSensitive, language } = params;
|
|
2414
2460
|
return `cts:element-query(xs:QName("${containerElementName}"),
|
|
@@ -2885,11 +2931,17 @@ function buildQueryPlan(params) {
|
|
|
2885
2931
|
}
|
|
2886
2932
|
if (compiledClause.candidateQueryVar != null) candidateQueryVars.push(compiledClause.candidateQueryVar);
|
|
2887
2933
|
if (index === 0) {
|
|
2888
|
-
predicateParts.push(
|
|
2934
|
+
predicateParts.push({
|
|
2935
|
+
operator: null,
|
|
2936
|
+
predicate: compiledClause.predicate
|
|
2937
|
+
});
|
|
2889
2938
|
index += groupedQueries?.length ?? 1;
|
|
2890
2939
|
continue;
|
|
2891
2940
|
}
|
|
2892
|
-
predicateParts.push(
|
|
2941
|
+
predicateParts.push({
|
|
2942
|
+
operator: query.operator ?? "OR",
|
|
2943
|
+
predicate: compiledClause.predicate
|
|
2944
|
+
});
|
|
2893
2945
|
index += groupedQueries?.length ?? 1;
|
|
2894
2946
|
}
|
|
2895
2947
|
if (hasCtsIncludesClauses) declarations.unshift(`let ${CTS_INCLUDES_STOP_WORDS_VAR} := (${CTS_INCLUDES_STOP_WORDS.map((stopWord) => stringLiteral(stopWord)).join(", ")})`);
|
|
@@ -2910,7 +2962,7 @@ function buildQueryPlan(params) {
|
|
|
2910
2962
|
return {
|
|
2911
2963
|
declarations,
|
|
2912
2964
|
itemsExpression,
|
|
2913
|
-
predicate: predicateParts
|
|
2965
|
+
predicate: buildGroupedPredicateExpression(buildPredicateGroups(predicateParts))
|
|
2914
2966
|
};
|
|
2915
2967
|
}
|
|
2916
2968
|
//#endregion
|