@delali/narsil 0.3.1-next.77 → 0.3.1-next.78
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/{chunk-HH6ALOUZ.mjs → chunk-55WEJKWT.mjs} +117 -17
- package/dist/{chunk-DFFQOA7S.mjs → chunk-DFW3U5UW.mjs} +134 -159
- package/dist/{chunk-V3B24XR7.mjs → chunk-IOZPBNSG.mjs} +2 -1
- package/dist/{chunk-D4EF7J3I.mjs → chunk-P2BEMMOD.mjs} +193 -58
- package/dist/{chunk-PXDY5VRT.mjs → chunk-PJWG547Z.mjs} +2 -2
- package/dist/{chunk-356UOTK2.mjs → chunk-PXDQFYD5.mjs} +7 -1
- package/dist/{chunk-G7IP3UDZ.mjs → chunk-R6WBLBTC.mjs} +45 -26
- package/dist/{chunk-PJU6EF22.mjs → chunk-RTR44V2A.mjs} +267 -108
- package/dist/{chunk-NO3ABFLE.mjs → chunk-WFVOBZS4.mjs} +2 -49
- package/dist/{chunk-BT62MUM5.mjs → chunk-XSZTF4ZQ.mjs} +1 -1
- package/dist/{chunk-BT6BI4GV.mjs → chunk-Z3BXCZXS.mjs} +1 -1
- package/dist/{direct-executor-Q7PNCGZB.mjs → direct-executor-WB2HKU4N.mjs} +6 -6
- package/dist/distribution.mjs +10 -10
- package/dist/index.browser.mjs +488 -260
- package/dist/index.mjs +9 -9
- package/dist/partial-words.mjs +3 -3
- package/dist/persistence/durability/checkpoint-worker.mjs +9 -9
- package/dist/server.mjs +6 -6
- package/dist/{thread-YOTNJEVY.mjs → thread-XBDVXKUE.mjs} +6 -6
- package/dist/workers/entry.mjs +3 -3
- package/package.json +7 -7
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { MAX_SORT_FIELDS, MAX_SORT_FIELD_NAME_LENGTH, MAX_CURSOR_LENGTH, MAX_CURSOR_ANCHOR_CODE_POINTS, RESULT_WINDOW, DEFAULT_FUZZY_PREFIX_LENGTH, MAX_FILTER_DEPTH, DEFAULT_PAGE_SIZE,
|
|
2
|
-
import {
|
|
3
|
-
import { getFlatSchema, tokenize, getFieldValueByInternalId, getFieldValueForDoc } from './chunk-
|
|
4
|
-
import {
|
|
1
|
+
import { MAX_FILTER_ARRAY_SIZE, GEO_UNIT_METRES, MAX_SORT_FIELDS, MAX_SORT_FIELD_NAME_LENGTH, MAX_CURSOR_LENGTH, MAX_CURSOR_ANCHOR_CODE_POINTS, RESULT_WINDOW, DEFAULT_FUZZY_PREFIX_LENGTH, MAX_FILTER_DEPTH, DEFAULT_PAGE_SIZE, MAX_FILTER_TESTS, PREFIX_MAX_EXPANSIONS, PARTIAL_WORD_MIN_CODE_POINTS, PARTIAL_WORDS_ADDED_PER_QUERY, FILTER_OPERAND_COPY_DEPTH } from './chunk-IOZPBNSG.mjs';
|
|
2
|
+
import { PATTERN_EXPRESSION_OPERATORS, PATTERN_TEST_OPERATORS, MAX_PATTERN_POSITIONS, isPatternTolerance, foldTypoText, typoRunsNeeded, distinctTypoRunCount, MAX_PATTERN_TEXT_CODE_POINTS, patternSearchModule, DEFAULT_PATTERN_WORK_CAP, bitsetIsEmpty, createBitSet, bitsetSet, PATTERN_WORK_FLUSH_UNITS, MATCHER_STATE_BUDGET_BYTES } from './chunk-4344I4MR.mjs';
|
|
3
|
+
import { getFlatSchema, tokenize, getFieldValueByInternalId, getFieldValueForDoc } from './chunk-WFVOBZS4.mjs';
|
|
4
|
+
import { parsedTypeOf, isLatitude, MAX_LATITUDE_DEGREES, isLongitude, MAX_LONGITUDE_DEGREES, MIN_POLYGON_POINTS, schemaFieldsOf, flattenSchema, isStringValuedBase, withSortableOption, isGeopointOrVectorType, EARTH_RADIUS_METERS, RADIUS_BOX_MARGIN_RATIO, RADIUS_BOX_MARGIN_RADIANS, FULL_TURN_DEGREES, ANTIMERIDIAN_SPAN_DEGREES, PROTOTYPE_POLLUTION_KEYS, DEG_TO_RAD, LOCATION_CODE_BITS_PER_AXIS, isWordIndexedFieldType, partialFieldsOf, MAX_COVERING_CELLS } from './chunk-PXDQFYD5.mjs';
|
|
5
5
|
import { fuzzyTermMatches } from './chunk-GES7U2PM.mjs';
|
|
6
|
-
import { appendFoldedCodePoint, compareCodePoints, sortModeOf, defaultSortMode, SORT_VALUE_MAX_CODE_POINTS, toReducedSortValue, readSortField, compareComparableKeys, toComparableSortValue,
|
|
6
|
+
import { appendFoldedCodePoint, foldedCodePointCount, exceedsCodePoints, singleFoldTable, compareCodePoints, sortModeOf, defaultSortMode, SORT_VALUE_MAX_CODE_POINTS, toReducedSortValue, readSortField, compareComparableKeys, toComparableSortValue, isSortMode, SORT_MODES, compareSortValues, codePointCount, holdsUnpairedSurrogate } from './chunk-IBR6634K.mjs';
|
|
7
7
|
import { NarsilError, ErrorCodes } from './chunk-I64LXKO3.mjs';
|
|
8
8
|
|
|
9
9
|
// src/core/pattern-index/platform.ts
|
|
@@ -567,6 +567,36 @@ function decodeCursorText(encoded) {
|
|
|
567
567
|
return new TextDecoder().decode(bytes);
|
|
568
568
|
}
|
|
569
569
|
|
|
570
|
+
// src/filters/keys.ts
|
|
571
|
+
var FILTER_EXPRESSION_KEYS = ["fields", "and", "or", "not"];
|
|
572
|
+
var FIELD_FILTER_OPERATORS = [
|
|
573
|
+
"eq",
|
|
574
|
+
"ne",
|
|
575
|
+
"gt",
|
|
576
|
+
"lt",
|
|
577
|
+
"gte",
|
|
578
|
+
"lte",
|
|
579
|
+
"between",
|
|
580
|
+
"in",
|
|
581
|
+
"nin",
|
|
582
|
+
"startsWith",
|
|
583
|
+
"endsWith",
|
|
584
|
+
"contains",
|
|
585
|
+
"wildcard",
|
|
586
|
+
"regex",
|
|
587
|
+
"caseFold",
|
|
588
|
+
"tolerance",
|
|
589
|
+
"containsAll",
|
|
590
|
+
"matchesAny",
|
|
591
|
+
"size",
|
|
592
|
+
"exists",
|
|
593
|
+
"notExists",
|
|
594
|
+
"isEmpty",
|
|
595
|
+
"isNotEmpty",
|
|
596
|
+
"radius",
|
|
597
|
+
"polygon"
|
|
598
|
+
];
|
|
599
|
+
|
|
570
600
|
// src/filters/operands/checks.ts
|
|
571
601
|
function operandKindOf(type) {
|
|
572
602
|
if (type === void 0) return void 0;
|
|
@@ -905,9 +935,19 @@ function requireGeoOperands(fieldPath, filter) {
|
|
|
905
935
|
}
|
|
906
936
|
|
|
907
937
|
// src/filters/operands/lists.ts
|
|
908
|
-
var WHOLE_VALUE_OPERATORS = [
|
|
938
|
+
var WHOLE_VALUE_OPERATORS = [
|
|
939
|
+
"eq",
|
|
940
|
+
"ne",
|
|
941
|
+
"in",
|
|
942
|
+
"nin",
|
|
943
|
+
"startsWith",
|
|
944
|
+
"endsWith",
|
|
945
|
+
"matchesAny",
|
|
946
|
+
"containsAll"
|
|
947
|
+
];
|
|
909
948
|
var ELEMENT_OPERATORS = ["matchesAny", "containsAll"];
|
|
910
949
|
var PRESENCE_OPERATORS = ["exists", "notExists", "isEmpty", "isNotEmpty"];
|
|
950
|
+
var SIZE_OPERAND_KEYS = ["size"];
|
|
911
951
|
var SIZE_OPERATORS = ["eq", "ne", "gt", "gte", "lt", "lte", "between"];
|
|
912
952
|
var SIZE_OPERATOR_SET = new Set(SIZE_OPERATORS);
|
|
913
953
|
var ELEMENT_KIND_BY_BASE = {
|
|
@@ -1044,6 +1084,14 @@ function requirePatternText(fieldPath, operator, text, caseFold) {
|
|
|
1044
1084
|
}
|
|
1045
1085
|
}
|
|
1046
1086
|
var ELEMENT_OPERATORS2 = ["matchesAny", "containsAll"];
|
|
1087
|
+
var PATTERN_OPERAND_KEYS = [
|
|
1088
|
+
"contains",
|
|
1089
|
+
"caseFold",
|
|
1090
|
+
"tolerance",
|
|
1091
|
+
...PATTERN_EXPRESSION_OPERATORS,
|
|
1092
|
+
...PATTERN_TEST_OPERATORS,
|
|
1093
|
+
...ELEMENT_OPERATORS2
|
|
1094
|
+
];
|
|
1047
1095
|
function requireExpressions(fieldPath, filter, type) {
|
|
1048
1096
|
for (const operator of PATTERN_EXPRESSION_OPERATORS) {
|
|
1049
1097
|
const pattern = filter[operator];
|
|
@@ -1119,18 +1167,20 @@ function requireTolerance(fieldPath, filter) {
|
|
|
1119
1167
|
{ fieldPath, operator: "tolerance", requiredRuns, distinctRuns }
|
|
1120
1168
|
);
|
|
1121
1169
|
}
|
|
1122
|
-
function
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1170
|
+
function requireWellFormedOperand(fieldPath, operator, text) {
|
|
1171
|
+
if (typeof text !== "string" || !holdsUnpairedSurrogate(text)) return;
|
|
1172
|
+
invalid(
|
|
1173
|
+
`The text of "${operator}" on field "${fieldPath}" holds an unpaired surrogate, the half of a character such as an emoji whose other half is missing, so no stored value can hold it`,
|
|
1174
|
+
fieldPath,
|
|
1175
|
+
operator
|
|
1176
|
+
);
|
|
1177
|
+
}
|
|
1178
|
+
function requireWellFormedText(fieldPath, operator, operand) {
|
|
1179
|
+
if (!Array.isArray(operand)) {
|
|
1180
|
+
requireWellFormedOperand(fieldPath, operator, operand);
|
|
1181
|
+
return;
|
|
1133
1182
|
}
|
|
1183
|
+
for (const text of operand) requireWellFormedOperand(fieldPath, operator, text);
|
|
1134
1184
|
}
|
|
1135
1185
|
|
|
1136
1186
|
// src/filters/operands/index.ts
|
|
@@ -1140,9 +1190,16 @@ var EQUALITY_OPERATORS = ["eq", "ne"];
|
|
|
1140
1190
|
var LIST_OPERATORS = ["in", "nin"];
|
|
1141
1191
|
var GEO_OPERATORS = ["radius", "polygon"];
|
|
1142
1192
|
var TEST_MODIFIERS = /* @__PURE__ */ new Set(["caseFold", "tolerance"]);
|
|
1193
|
+
var EXPRESSION_KEYS = new Set(FILTER_EXPRESSION_KEYS);
|
|
1194
|
+
var OPERATOR_KEYS = new Set(FIELD_FILTER_OPERATORS);
|
|
1195
|
+
var PROTOTYPE_KEY = "__proto__";
|
|
1196
|
+
var validatedFilters = /* @__PURE__ */ new WeakMap();
|
|
1143
1197
|
function invalidShape(message) {
|
|
1144
1198
|
throw new NarsilError(ErrorCodes.SEARCH_INVALID_FILTER, message);
|
|
1145
1199
|
}
|
|
1200
|
+
function invalidKey(message, key) {
|
|
1201
|
+
throw new NarsilError(ErrorCodes.SEARCH_INVALID_FILTER, message, { key });
|
|
1202
|
+
}
|
|
1146
1203
|
function undeclaredFieldOnStrictIndex(field, option) {
|
|
1147
1204
|
return new NarsilError(
|
|
1148
1205
|
ErrorCodes.SEARCH_INVALID_FIELD,
|
|
@@ -1219,21 +1276,52 @@ function requireValueOperands(fieldPath, filter, type) {
|
|
|
1219
1276
|
if (filter[operator] !== void 0) requireFieldKind(fieldPath, operator, type, ["geopoint"]);
|
|
1220
1277
|
}
|
|
1221
1278
|
}
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1279
|
+
var OPERAND_CHECKS = [
|
|
1280
|
+
[[...RANGE_OPERATORS, "between"], requireRangeOperands],
|
|
1281
|
+
[[...TEXT_OPERATORS, ...EQUALITY_OPERATORS, ...LIST_OPERATORS, ...GEO_OPERATORS], requireValueOperands],
|
|
1282
|
+
[WHOLE_VALUE_OPERATORS, requireWholeValueIndex],
|
|
1283
|
+
[PRESENCE_OPERATORS, requirePresenceOperands],
|
|
1284
|
+
[ELEMENT_OPERATORS, requireElementOperands],
|
|
1285
|
+
[SIZE_OPERAND_KEYS, requireSizeOperands],
|
|
1286
|
+
[PATTERN_OPERAND_KEYS, requirePatternOperands],
|
|
1287
|
+
[GEO_OPERATORS, requireGeoOperands]
|
|
1288
|
+
];
|
|
1289
|
+
var CHECKS_BY_OPERATOR = checksByOperator();
|
|
1290
|
+
function checksByOperator() {
|
|
1291
|
+
const checks = /* @__PURE__ */ new Map();
|
|
1292
|
+
for (let at = 0; at < OPERAND_CHECKS.length; at++) {
|
|
1293
|
+
for (const operator of OPERAND_CHECKS[at][0]) checks.set(operator, (checks.get(operator) ?? 0) | 1 << at);
|
|
1294
|
+
}
|
|
1295
|
+
return checks;
|
|
1296
|
+
}
|
|
1297
|
+
function testsOfOperator(operator, operand) {
|
|
1298
|
+
if (TEST_MODIFIERS.has(operator)) return 0;
|
|
1299
|
+
return operator === "size" && isObjectRecord(operand) ? Math.max(1, Object.keys(operand).length) : 1;
|
|
1300
|
+
}
|
|
1301
|
+
function requireValidFieldTests(fieldPath, filter, type, walk) {
|
|
1302
|
+
const operators = Object.keys(filter);
|
|
1303
|
+
let wanted = 0;
|
|
1304
|
+
let tests = 0;
|
|
1305
|
+
for (const operator of operators) {
|
|
1306
|
+
if (walk.unknownKey === null && !OPERATOR_KEYS.has(operator)) {
|
|
1307
|
+
walk.unknownKey = {
|
|
1308
|
+
message: `Field "${fieldPath}" is tested with "${operator}", which is no filter operator`,
|
|
1309
|
+
key: operator
|
|
1310
|
+
};
|
|
1311
|
+
}
|
|
1312
|
+
tests += testsOfOperator(operator, filter[operator]);
|
|
1313
|
+
wanted |= CHECKS_BY_OPERATOR.get(operator) ?? 0;
|
|
1314
|
+
}
|
|
1315
|
+
countTests(walk, Math.max(1, tests));
|
|
1316
|
+
for (const operator of operators) requireWellFormedText(fieldPath, operator, filter[operator]);
|
|
1317
|
+
for (let at = 0; wanted !== 0; at++, wanted >>>= 1) {
|
|
1318
|
+
if ((wanted & 1) !== 0) OPERAND_CHECKS[at][1](fieldPath, filter, type);
|
|
1319
|
+
}
|
|
1232
1320
|
}
|
|
1233
1321
|
function filterTestCount(expression) {
|
|
1234
1322
|
if (!isObjectRecord(expression)) return 0;
|
|
1235
1323
|
const fieldFilters = isObjectRecord(expression.fields) ? Object.values(expression.fields) : [];
|
|
1236
|
-
let tests = fieldFilters.length === 0 && !holdsNestedExpressions(expression) ? 1 : 0;
|
|
1324
|
+
let tests = fieldFilters.length === 0 && !holdsNestedExpressions(expression.and, expression.or, expression.not) ? 1 : 0;
|
|
1237
1325
|
for (const filter of fieldFilters) tests += isObjectRecord(filter) ? testsIn(filter) : 1;
|
|
1238
1326
|
for (const list of [expression.and, expression.or]) {
|
|
1239
1327
|
if (Array.isArray(list)) for (const nested of list) tests += filterTestCount(nested);
|
|
@@ -1242,10 +1330,7 @@ function filterTestCount(expression) {
|
|
|
1242
1330
|
}
|
|
1243
1331
|
function testsIn(filter) {
|
|
1244
1332
|
let tests = 0;
|
|
1245
|
-
for (const [operator, operand] of Object.entries(filter))
|
|
1246
|
-
if (TEST_MODIFIERS.has(operator)) continue;
|
|
1247
|
-
tests += operator === "size" && isObjectRecord(operand) ? Math.max(1, Object.keys(operand).length) : 1;
|
|
1248
|
-
}
|
|
1333
|
+
for (const [operator, operand] of Object.entries(filter)) tests += testsOfOperator(operator, operand);
|
|
1249
1334
|
return Math.max(1, tests);
|
|
1250
1335
|
}
|
|
1251
1336
|
function countTests(walk, tests) {
|
|
@@ -1254,39 +1339,89 @@ function countTests(walk, tests) {
|
|
|
1254
1339
|
invalidShape(`A filter holds at most ${MAX_FILTER_TESTS} tests across all of its fields and nested expressions`);
|
|
1255
1340
|
}
|
|
1256
1341
|
}
|
|
1257
|
-
function holdsNestedExpressions(
|
|
1258
|
-
const { and, or, not } = expression;
|
|
1342
|
+
function holdsNestedExpressions(and, or, not) {
|
|
1259
1343
|
return Array.isArray(and) && and.length > 0 || Array.isArray(or) && or.length > 0 || not !== void 0;
|
|
1260
1344
|
}
|
|
1261
|
-
function
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1345
|
+
function noteUnknownExpressionKey(expression, walk) {
|
|
1346
|
+
for (const key in expression) {
|
|
1347
|
+
if (!Object.hasOwn(expression, key) || EXPRESSION_KEYS.has(key)) continue;
|
|
1348
|
+
walk.unknownKey = {
|
|
1349
|
+
message: `A filter expression takes "fields", "and", "or", and "not", and "${key}" is none of them. A per-field test such as { ${key}: { eq: ... } } belongs under "fields"`,
|
|
1350
|
+
key
|
|
1351
|
+
};
|
|
1352
|
+
return;
|
|
1353
|
+
}
|
|
1354
|
+
}
|
|
1355
|
+
function setOwn(record, key, value) {
|
|
1356
|
+
if (key === PROTOTYPE_KEY) {
|
|
1357
|
+
Object.defineProperty(record, key, { value, enumerable: true, writable: true, configurable: true });
|
|
1358
|
+
} else {
|
|
1359
|
+
record[key] = value;
|
|
1360
|
+
}
|
|
1361
|
+
}
|
|
1362
|
+
function ownedOperandOf(value, fieldPath, operator, depth) {
|
|
1363
|
+
if (typeof value !== "object" || value === null || depth > FILTER_OPERAND_COPY_DEPTH) return value;
|
|
1364
|
+
if (Array.isArray(value)) {
|
|
1365
|
+
requireListLength(fieldPath, operator, value);
|
|
1366
|
+
const owned2 = [];
|
|
1367
|
+
for (let at = 0; at < value.length; at++) owned2.push(ownedOperandOf(value[at], fieldPath, operator, depth + 1));
|
|
1368
|
+
return owned2;
|
|
1369
|
+
}
|
|
1370
|
+
const record = value;
|
|
1371
|
+
const owned = {};
|
|
1372
|
+
for (const key of Object.keys(record)) setOwn(owned, key, ownedOperandOf(record[key], fieldPath, operator, depth + 1));
|
|
1373
|
+
return owned;
|
|
1374
|
+
}
|
|
1375
|
+
function ownedFieldFilterOf(fieldPath, filter) {
|
|
1376
|
+
const owned = {};
|
|
1377
|
+
for (const operator of Object.keys(filter)) {
|
|
1378
|
+
setOwn(owned, operator, ownedOperandOf(filter[operator], fieldPath, operator, 1));
|
|
1267
1379
|
}
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1380
|
+
return owned;
|
|
1381
|
+
}
|
|
1382
|
+
function ownedFieldFiltersOf(fields, walk) {
|
|
1383
|
+
const owned = {};
|
|
1384
|
+
for (const fieldPath of Object.keys(fields)) {
|
|
1271
1385
|
const type = walk.fieldTypes[fieldPath];
|
|
1272
1386
|
if (!Object.hasOwn(walk.fieldTypes, fieldPath) || type === void 0) throw undeclaredFilterField(fieldPath);
|
|
1387
|
+
const filter = fields[fieldPath];
|
|
1273
1388
|
if (!isObjectRecord(filter)) invalidShape(`The filter on field "${fieldPath}" must be an object of tests`);
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
for (const [clause, list] of [
|
|
1278
|
-
["and", and],
|
|
1279
|
-
["or", or]
|
|
1280
|
-
]) {
|
|
1281
|
-
if (list === void 0) continue;
|
|
1282
|
-
if (!Array.isArray(list)) invalidShape(`"${clause}" in a filter expression must be a list of filter expressions`);
|
|
1283
|
-
for (const nested of list) requireValidExpression(nested, walk, depth + 1);
|
|
1389
|
+
const ownedFilter = ownedFieldFilterOf(fieldPath, filter);
|
|
1390
|
+
requireValidFieldTests(fieldPath, ownedFilter, type, walk);
|
|
1391
|
+
setOwn(owned, fieldPath, ownedFilter);
|
|
1284
1392
|
}
|
|
1285
|
-
|
|
1393
|
+
return owned;
|
|
1286
1394
|
}
|
|
1287
|
-
function
|
|
1288
|
-
if (
|
|
1289
|
-
|
|
1395
|
+
function ownedClauseOf(clause, list, walk, depth) {
|
|
1396
|
+
if (!Array.isArray(list)) invalidShape(`"${clause}" in a filter expression must be a list of filter expressions`);
|
|
1397
|
+
const owned = [];
|
|
1398
|
+
for (let at = 0; at < list.length; at++) owned.push(ownedExpressionOf(list[at], walk, depth + 1));
|
|
1399
|
+
return owned;
|
|
1400
|
+
}
|
|
1401
|
+
function ownedExpressionOf(expression, walk, depth) {
|
|
1402
|
+
if (depth > MAX_FILTER_DEPTH) invalidShape(`A filter expression nests at most ${MAX_FILTER_DEPTH} levels deep`);
|
|
1403
|
+
if (!isObjectRecord(expression)) invalidShape("Each filter expression must be an object");
|
|
1404
|
+
if (walk.unknownKey === null) noteUnknownExpressionKey(expression, walk);
|
|
1405
|
+
const { fields, and, or, not } = expression;
|
|
1406
|
+
if (fields !== void 0 && !isObjectRecord(fields)) {
|
|
1407
|
+
invalidShape('"fields" in a filter expression must be an object keyed by field path');
|
|
1408
|
+
}
|
|
1409
|
+
const owned = {};
|
|
1410
|
+
const fieldCount = fields === void 0 ? 0 : Object.keys(fields).length;
|
|
1411
|
+
if (fieldCount === 0 && !holdsNestedExpressions(and, or, not)) countTests(walk, 1);
|
|
1412
|
+
if (fields !== void 0) owned.fields = ownedFieldFiltersOf(fields, walk);
|
|
1413
|
+
if (and !== void 0) owned.and = ownedClauseOf("and", and, walk, depth);
|
|
1414
|
+
if (or !== void 0) owned.or = ownedClauseOf("or", or, walk, depth);
|
|
1415
|
+
if (not !== void 0) owned.not = ownedExpressionOf(not, walk, depth + 1);
|
|
1416
|
+
return owned;
|
|
1417
|
+
}
|
|
1418
|
+
function validatedFilterOf(expression, fieldTypes) {
|
|
1419
|
+
if (validatedFilters.get(expression) === fieldTypes) return expression;
|
|
1420
|
+
const walk = { fieldTypes, tests: 0, unknownKey: null };
|
|
1421
|
+
const validated = ownedExpressionOf(expression, walk, 0);
|
|
1422
|
+
if (walk.unknownKey !== null) invalidKey(walk.unknownKey.message, walk.unknownKey.key);
|
|
1423
|
+
validatedFilters.set(validated, fieldTypes);
|
|
1424
|
+
return validated;
|
|
1290
1425
|
}
|
|
1291
1426
|
|
|
1292
1427
|
// src/search/sorting.ts
|
|
@@ -2185,4 +2320,4 @@ function setNestedValue(obj, path, value) {
|
|
|
2185
2320
|
current[segments[segments.length - 1]] = value;
|
|
2186
2321
|
}
|
|
2187
2322
|
|
|
2188
|
-
export { PATTERN_HOST, applyPagination, applyProjection, applySorting, availablePatternSearch, clampRowCount, cloneProjected, collectQueryTermStats, computeFacets, countsWithoutScores, coveringRanges, createPatternWorkMeter, decodePageCursor, encodePageCursor, everyValueFacetConfig, fanOutMatchCount, fanOutQuery, filterTestCount, fnv1a, fnv1aBytes, fnv1aUint32s, fulltextMatches, joinPatternWorkMeter, kWayMerge, locationCode, mergeFacets, mergePartitionStats, normalizeSort, oversampledFacetConfig, oversampledShardSize, partitionsIn, patternIndexOf, polygonBoxes, polygonContainment, projectionKeepsField, pruneStatsToQueryTerms, radiusBoxes, readSortValues, registerPatternSearch, requireMatchingCursor, requirePatternSearch, requirePatternSearchFor, requireSortableFields,
|
|
2323
|
+
export { FIELD_FILTER_OPERATORS, FILTER_EXPRESSION_KEYS, PATTERN_HOST, applyPagination, applyProjection, applySorting, availablePatternSearch, clampRowCount, cloneProjected, collectQueryTermStats, computeFacets, countsWithoutScores, coveringRanges, createPatternWorkMeter, decodePageCursor, encodePageCursor, everyValueFacetConfig, fanOutMatchCount, fanOutQuery, filterTestCount, fnv1a, fnv1aBytes, fnv1aUint32s, fulltextMatches, joinPatternWorkMeter, kWayMerge, locationCode, mergeFacets, mergePartitionStats, normalizeSort, oversampledFacetConfig, oversampledShardSize, partitionsIn, patternIndexOf, polygonBoxes, polygonContainment, projectionKeepsField, pruneStatsToQueryTerms, radiusBoxes, readSortValues, registerPatternSearch, requireMatchingCursor, requirePatternSearch, requirePatternSearchFor, requireSortableFields, requireWithinResultWindow, resolveProjection, sanitizeGlobalStats, setNestedValue, sortModesOf, sortSignatureEntry, sortSignatureOf, undeclaredFieldOnStrictIndex, undeclaredFilterField, validatedFilterOf };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { readSharedConfigFields, restoredEmbedding, restoredPartitionConfig, MAX_PARTITION_COUNT, MAX_REPLICATION_FACTOR } from './chunk-
|
|
1
|
+
import { readSharedConfigFields, restoredEmbedding, restoredPartitionConfig, MAX_PARTITION_COUNT, MAX_REPLICATION_FACTOR } from './chunk-XSZTF4ZQ.mjs';
|
|
2
2
|
import { getLanguage } from './chunk-4MQ5F4IL.mjs';
|
|
3
|
-
import { MAX_INDEX_NAME_LENGTH, INDEX_NAME_PATTERN } from './chunk-
|
|
3
|
+
import { MAX_INDEX_NAME_LENGTH, INDEX_NAME_PATTERN } from './chunk-IOZPBNSG.mjs';
|
|
4
4
|
import { compareCodePoints } from './chunk-IBR6634K.mjs';
|
|
5
5
|
import { NarsilError, ErrorCodes } from './chunk-I64LXKO3.mjs';
|
|
6
6
|
import { encode, decode } from '@msgpack/msgpack';
|
|
@@ -13,6 +13,7 @@ var MAX_VECTOR_DIMENSION = 4096;
|
|
|
13
13
|
var MAX_STORED_VECTOR_DIMENSION = 65535;
|
|
14
14
|
var MAX_TEXT_FIELDS = 65536;
|
|
15
15
|
var MAX_DOCUMENT_BYTES = 16777216;
|
|
16
|
+
var PARSED_FIELD_TYPE_CACHE_ENTRIES = 1024;
|
|
16
17
|
|
|
17
18
|
// src/schema/validator/shared.ts
|
|
18
19
|
var VECTOR_PATTERN = /^vector\[(\d+)]$/;
|
|
@@ -103,10 +104,15 @@ function parseFieldType(type, path) {
|
|
|
103
104
|
dimension
|
|
104
105
|
};
|
|
105
106
|
}
|
|
107
|
+
var parsedTypesByName = /* @__PURE__ */ new Map();
|
|
106
108
|
function parsedTypeOf(type) {
|
|
107
109
|
if (type === void 0) return void 0;
|
|
110
|
+
const known = parsedTypesByName.get(type);
|
|
111
|
+
if (known !== void 0) return known;
|
|
108
112
|
try {
|
|
109
|
-
|
|
113
|
+
const parsed = Object.freeze(parseFieldType(type, ""));
|
|
114
|
+
if (parsedTypesByName.size < PARSED_FIELD_TYPE_CACHE_ENTRIES) parsedTypesByName.set(type, parsed);
|
|
115
|
+
return parsed;
|
|
110
116
|
} catch {
|
|
111
117
|
return void 0;
|
|
112
118
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { clampRowCount, sortSignatureOf, requireSortableFields, decodePageCursor, requireMatchingCursor, resolveProjection, encodePageCursor, requireWithinResultWindow, normalizeSort, fanOutQuery, sortModesOf, applySorting, applyPagination, projectionKeepsField, countsWithoutScores, fanOutMatchCount, fnv1aBytes,
|
|
2
|
-
import { MAX_INDEX_NAME_LENGTH, INDEX_NAME_PATTERN, MAX_DOC_ID_LENGTH, DEFAULT_LIMIT, DEFAULT_MAX_PER_GROUP, DEFAULT_SUGGEST_LIMIT, MAX_SUGGEST_LIMIT, MAX_SUGGEST_SCATTER_LIMIT, ABSOLUTE_WINDOWS_PATH_PATTERN, MODULE_URL_SCHEME_PATTERN, DEFAULT_LINEAR_ALPHA, MIN_LINEAR_ALPHA, MAX_LINEAR_ALPHA, DEFAULT_RANK_CONSTANT, MIN_RANK_CONSTANT, DEFAULT_OFFSET, DEFAULT_FUZZY_PREFIX_LENGTH, RESULT_WINDOW, PARTIAL_WORD_MIN_CODE_POINTS, PARTIAL_WORDS_ADDED_PER_QUERY, MAX_TOLERANCE, MAX_PREFIX_LENGTH } from './chunk-
|
|
1
|
+
import { clampRowCount, sortSignatureOf, requireSortableFields, decodePageCursor, requireMatchingCursor, resolveProjection, encodePageCursor, requireWithinResultWindow, normalizeSort, fanOutQuery, sortModesOf, applySorting, applyPagination, projectionKeepsField, countsWithoutScores, fanOutMatchCount, fnv1aBytes, validatedFilterOf, createPatternWorkMeter, everyValueFacetConfig, fulltextMatches, mergeFacets, pruneStatsToQueryTerms, partitionsIn, undeclaredFieldOnStrictIndex } from './chunk-P2BEMMOD.mjs';
|
|
2
|
+
import { MAX_INDEX_NAME_LENGTH, INDEX_NAME_PATTERN, MAX_DOC_ID_LENGTH, DEFAULT_LIMIT, DEFAULT_MAX_PER_GROUP, DEFAULT_SUGGEST_LIMIT, MAX_SUGGEST_LIMIT, MAX_SUGGEST_SCATTER_LIMIT, ABSOLUTE_WINDOWS_PATH_PATTERN, MODULE_URL_SCHEME_PATTERN, DEFAULT_LINEAR_ALPHA, MIN_LINEAR_ALPHA, MAX_LINEAR_ALPHA, DEFAULT_RANK_CONSTANT, MIN_RANK_CONSTANT, DEFAULT_OFFSET, DEFAULT_FUZZY_PREFIX_LENGTH, RESULT_WINDOW, PARTIAL_WORD_MIN_CODE_POINTS, PARTIAL_WORDS_ADDED_PER_QUERY, MAX_TOLERANCE, MAX_PREFIX_LENGTH } from './chunk-IOZPBNSG.mjs';
|
|
3
3
|
import { MIN_OVERSAMPLE } from './chunk-ZJ4CSAB2.mjs';
|
|
4
|
-
import { tokenize } from './chunk-
|
|
5
|
-
import { partialFieldsOf, MIN_PATTERN_VALUE_LIMIT, MAX_PATTERN_VALUE_LIMIT, flattenSchema, isWordIndexedFieldType, isGeopointOrVectorType } from './chunk-
|
|
4
|
+
import { tokenize } from './chunk-WFVOBZS4.mjs';
|
|
5
|
+
import { partialFieldsOf, MIN_PATTERN_VALUE_LIMIT, MAX_PATTERN_VALUE_LIMIT, flattenSchema, isWordIndexedFieldType, isGeopointOrVectorType } from './chunk-PXDQFYD5.mjs';
|
|
6
6
|
import { fuzzyTermMatches } from './chunk-GES7U2PM.mjs';
|
|
7
7
|
import { holdsUnpairedSurrogate, compareCodePoints, compareComparableKeys, codePointCount } from './chunk-IBR6634K.mjs';
|
|
8
8
|
import { NarsilError, ErrorCodes } from './chunk-I64LXKO3.mjs';
|
|
@@ -16,6 +16,8 @@ var NUMBER_TAG = 4;
|
|
|
16
16
|
var STRING_TAG = 5;
|
|
17
17
|
var LIST_TAG = 6;
|
|
18
18
|
var MAP_TAG = 7;
|
|
19
|
+
var LENGTH_BYTES = 4;
|
|
20
|
+
var LAST_ASCII_UNIT = 127;
|
|
19
21
|
var encoder = new TextEncoder();
|
|
20
22
|
function ensureCapacity(stream, extra) {
|
|
21
23
|
if (stream.length + extra <= stream.bytes.length) return;
|
|
@@ -45,13 +47,28 @@ function writeNumber(stream, value) {
|
|
|
45
47
|
}
|
|
46
48
|
stream.length += 8;
|
|
47
49
|
}
|
|
48
|
-
function
|
|
50
|
+
function writeEncodedString(stream, value) {
|
|
49
51
|
const encoded = encoder.encode(value);
|
|
50
52
|
writeUint32(stream, encoded.length);
|
|
51
53
|
ensureCapacity(stream, encoded.length);
|
|
52
54
|
stream.bytes.set(encoded, stream.length);
|
|
53
55
|
stream.length += encoded.length;
|
|
54
56
|
}
|
|
57
|
+
function writeString(stream, value) {
|
|
58
|
+
ensureCapacity(stream, LENGTH_BYTES + value.length);
|
|
59
|
+
const start = stream.length + LENGTH_BYTES;
|
|
60
|
+
const bytes = stream.bytes;
|
|
61
|
+
for (let at = 0; at < value.length; at++) {
|
|
62
|
+
const unit = value.charCodeAt(at);
|
|
63
|
+
if (unit > LAST_ASCII_UNIT) {
|
|
64
|
+
writeEncodedString(stream, value);
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
bytes[start + at] = unit;
|
|
68
|
+
}
|
|
69
|
+
writeUint32(stream, value.length);
|
|
70
|
+
stream.length += value.length;
|
|
71
|
+
}
|
|
55
72
|
var NumberList = class {
|
|
56
73
|
constructor(members) {
|
|
57
74
|
this.members = members;
|
|
@@ -328,16 +345,18 @@ function requireBooleanPartialWords(params) {
|
|
|
328
345
|
received: setting === null ? "null" : typeof setting
|
|
329
346
|
});
|
|
330
347
|
}
|
|
331
|
-
function
|
|
348
|
+
function validQueryParams(params, config) {
|
|
332
349
|
const strict = config.strict === true;
|
|
333
350
|
requireValidTypoTolerance(params);
|
|
334
351
|
requireBooleanPartialWords(params);
|
|
335
352
|
requireSortableFields(params.sort, config.schema, strict);
|
|
336
|
-
|
|
353
|
+
const filters = validQueryFilter(params.filters, config.schema);
|
|
337
354
|
requireUsableQueryFields(params, config.schema, strict);
|
|
355
|
+
return filters === params.filters ? params : { ...params, filters };
|
|
338
356
|
}
|
|
339
|
-
function
|
|
340
|
-
if (filters
|
|
357
|
+
function validQueryFilter(filters, schema) {
|
|
358
|
+
if (filters === void 0 || filters === null) return filters;
|
|
359
|
+
return validatedFilterOf(filters, flattenSchema(schema));
|
|
341
360
|
}
|
|
342
361
|
function requireVectorSearchable(params, context, needsVector) {
|
|
343
362
|
if (!needsVector) return;
|
|
@@ -606,7 +625,7 @@ function executeListDocuments(params, context) {
|
|
|
606
625
|
const limit = clampListLimit(params.limit);
|
|
607
626
|
const signature = sortSignatureOf(params.sort);
|
|
608
627
|
requireSortableFields(params.sort, schema, context.strict === true);
|
|
609
|
-
|
|
628
|
+
const filters = validQueryFilter(params.filters, schema);
|
|
610
629
|
const binding = listBindingOf(params.filters);
|
|
611
630
|
let cursor = null;
|
|
612
631
|
if (params.cursor !== void 0) {
|
|
@@ -614,7 +633,7 @@ function executeListDocuments(params, context) {
|
|
|
614
633
|
requireMatchingCursor(cursor, params.cursor, signature, false, binding);
|
|
615
634
|
}
|
|
616
635
|
const partitions = context.partitionIds === void 0 ? manager.getAllPartitions() : context.partitionIds.map((partitionId) => manager.partitionAt(partitionId)).filter((partition) => partition !== void 0);
|
|
617
|
-
const filtered =
|
|
636
|
+
const filtered = filters === void 0 ? null : collectFilterMatches(partitions, filters, schema, context.patternWorkCap);
|
|
618
637
|
const total = filtered === null ? countAcrossPartitions(manager, context.partitionIds, partitions) : filtered.total;
|
|
619
638
|
const page = params.sort === void 0 || signature === null ? pageInIdOrder(partitions, cursor, filtered, limit, binding) : pageInSortOrder(partitions, cursor, filtered, limit, params.sort, signature, schema, binding);
|
|
620
639
|
const projection = resolveProjection(params.document);
|
|
@@ -1351,28 +1370,28 @@ function requireCursorDepth(cursor, signature, binding) {
|
|
|
1351
1370
|
requireMatchingCursor(decoded, cursor, signature, true, binding);
|
|
1352
1371
|
return decoded.depth ?? 0;
|
|
1353
1372
|
}
|
|
1354
|
-
async function executeQuery(
|
|
1373
|
+
async function executeQuery(request, callerContext) {
|
|
1355
1374
|
const context = withPatternWork(callerContext);
|
|
1356
1375
|
const { manager, language, config, workerSearch, indexName } = context;
|
|
1357
1376
|
const startTime = now();
|
|
1358
|
-
const limit = clampLimit(
|
|
1359
|
-
const offset = clampOffset(
|
|
1377
|
+
const limit = clampLimit(request.limit);
|
|
1378
|
+
const offset = clampOffset(request.offset);
|
|
1360
1379
|
requireWithinResultWindow(limit, offset);
|
|
1361
|
-
const sortFields = normalizeSort(
|
|
1362
|
-
requireKnownMode(
|
|
1363
|
-
const sortSignature = sortSignatureOf(
|
|
1364
|
-
const hasTerm =
|
|
1365
|
-
const hasVector =
|
|
1366
|
-
const isHybridMode =
|
|
1367
|
-
const isVectorOnly = (
|
|
1368
|
-
if (sortSignature !== null && (isHybridMode ||
|
|
1380
|
+
const sortFields = normalizeSort(request.sort);
|
|
1381
|
+
requireKnownMode(request);
|
|
1382
|
+
const sortSignature = sortSignatureOf(request.sort);
|
|
1383
|
+
const hasTerm = request.term !== void 0 && request.term.trim().length > 0;
|
|
1384
|
+
const hasVector = request.vector !== void 0 && request.vector.value !== void 0;
|
|
1385
|
+
const isHybridMode = request.mode === "hybrid" || hasTerm && hasVector;
|
|
1386
|
+
const isVectorOnly = (request.mode === "vector" || hasVector && !hasTerm) && !isHybridMode;
|
|
1387
|
+
if (sortSignature !== null && (isHybridMode || request.hybrid !== void 0)) {
|
|
1369
1388
|
throw new NarsilError(
|
|
1370
1389
|
ErrorCodes.SEARCH_INVALID_MODE,
|
|
1371
1390
|
"A hybrid query cannot carry a sort, because fusion defines the order of hybrid results",
|
|
1372
1391
|
{ sort: sortFields.map((entry) => entry.field) }
|
|
1373
1392
|
);
|
|
1374
1393
|
}
|
|
1375
|
-
|
|
1394
|
+
const params = validQueryParams(request, config);
|
|
1376
1395
|
requireVectorSearchable(params, context, isVectorOnly || isHybridMode);
|
|
1377
1396
|
let paginated;
|
|
1378
1397
|
let nextCursor;
|
|
@@ -1535,12 +1554,12 @@ async function executeQuery(params, callerContext) {
|
|
|
1535
1554
|
coverage: coverageFor(manager, context.partitionIds)
|
|
1536
1555
|
};
|
|
1537
1556
|
}
|
|
1538
|
-
async function executePreflight(
|
|
1557
|
+
async function executePreflight(request, callerContext) {
|
|
1539
1558
|
const context = withPatternWork(callerContext);
|
|
1540
1559
|
const { manager, language, config, workerSearch, indexName } = context;
|
|
1541
1560
|
const startTime = now();
|
|
1542
|
-
requireKnownMode(
|
|
1543
|
-
|
|
1561
|
+
requireKnownMode(request);
|
|
1562
|
+
const params = validQueryParams(request, config);
|
|
1544
1563
|
const hasTerm = params.term !== void 0 && params.term.trim().length > 0;
|
|
1545
1564
|
const hasVector = params.vector !== void 0 && params.vector.value !== void 0;
|
|
1546
1565
|
const isHybridMode = params.mode === "hybrid" || hasTerm && hasVector;
|