@atscript/db-mongo 0.1.185 → 0.1.186

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/agg.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_mongo_accumulator = require("./mongo-accumulator-BBRS2_8v.cjs");
2
+ const require_mongo_accumulator = require("./mongo-accumulator-CAkmw604.cjs");
3
3
  let _atscript_db = require("@atscript/db");
4
4
  let _uniqu_core = require("@uniqu/core");
5
5
  let _atscript_db_agg = require("@atscript/db/agg");
package/dist/agg.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { d as rowOrderStages, f as sortStages, g as whereToExpr, i as buildMongoFilter, m as orNull, n as distinctCountExpr, p as exprToMongo, s as mongoFilterStages, t as buildAccumulator } from "./mongo-accumulator-CFVRBDiw.mjs";
1
+ import { d as rowOrderStages, f as sortStages, g as whereToExpr, i as buildMongoFilter, m as orNull, n as distinctCountExpr, p as exprToMongo, s as mongoFilterStages, t as buildAccumulator } from "./mongo-accumulator-BDgJ8wpS.mjs";
2
2
  import { DbError, aggregateColumns, evaluateExpr } from "@atscript/db";
3
3
  import { BUCKET_MAX_INSTANT, BUCKET_MIN_INSTANT } from "@uniqu/core";
4
4
  import { assertAggregateFn, resolveAlias } from "@atscript/db/agg";
package/dist/index.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_mongo_accumulator = require("./mongo-accumulator-BBRS2_8v.cjs");
2
+ const require_mongo_accumulator = require("./mongo-accumulator-CAkmw604.cjs");
3
3
  const require_search_messages = require("./search-messages-BqLxxrb8.cjs");
4
4
  let _atscript_db = require("@atscript/db");
5
5
  let mongodb = require("mongodb");
@@ -1331,9 +1331,9 @@ function requireSearchStage(host, text, indexName, controls) {
1331
1331
  * path). `$index` picks the search index by the same rules as `search()`, and
1332
1332
  * an unresolvable one throws exactly as the leaf path does.
1333
1333
  *
1334
- * `classicText` is deliberately dropped: it only drives the leaf runner's
1335
- * relevance order (the `textScore` it sorts by), and no per-document score
1336
- * survives `$group`. See `resolveAggregateSearch` in `@atscript/db/agg` for
1334
+ * The plan's `relevance` order is deliberately dropped: it only orders the
1335
+ * leaf runner's rows, and no per-document score survives `$group`. See
1336
+ * `resolveAggregateSearch` in `@atscript/db/agg` for
1337
1337
  * the normative cross-adapter contract.
1338
1338
  */
1339
1339
  function buildAggregateSearchStage(host, controls) {
@@ -1352,33 +1352,46 @@ async function searchWithCountImpl(host, text, query, indexName) {
1352
1352
  return runSearchWithCountPipeline(host, plan.stage, query, "searchWithCount", textRunOptions(plan, query));
1353
1353
  }
1354
1354
  /**
1355
- * The runner options of a text search: relevance from `textScore` for a
1356
- * classic `$text` match — none under `$rank: false` (since 0.1.175), which
1357
- * orders by `_id` instead (an Atlas `$search` included).
1355
+ * The runner options of a text search: the plan's relevance order — none
1356
+ * under `$rank: false` (since 0.1.175), which orders by `_id` instead (an
1357
+ * Atlas `$search` included).
1358
1358
  */
1359
1359
  function textRunOptions(plan, query) {
1360
1360
  if (query.controls?.$rank === false) return { defaultOrder: UNRANKED_ORDER };
1361
- return plan.classicText ? { defaultOrder: RELEVANCE_ORDER } : {};
1361
+ return { defaultOrder: plan.relevance };
1362
1362
  }
1363
1363
  /**
1364
1364
  * Field a search score rides in through the pipeline: the `vectorSearchScore`
1365
1365
  * (renamed to the public `$score` after fetch — a field name cannot start
1366
- * with `$`) or the `textScore` of a relevance order (dropped from the rows).
1366
+ * with `$`) or the score of a relevance order (dropped from the rows).
1367
1367
  */
1368
1368
  const SCORE_FIELD = "__atscript_score";
1369
1369
  /**
1370
- * Classic `$text` relevance order: `textScore` descending, `_id` breaking ties
1371
- * (since 0.1.165). The score is dropped after `$skip` / `$limit`, so a row
1372
- * carries no score field (since 0.1.185; before, rows carried `_score`).
1370
+ * Classic `$text` relevance order: the rows an integer member matched by
1371
+ * exact number first (`exact`: one `$eq` expression per member of a
1372
+ * whole-number search, since 0.1.186 — as the SQL adapters order them), then
1373
+ * `textScore` descending, `_id` breaking ties (since 0.1.165). The score is
1374
+ * dropped after `$skip` / `$limit`, so a row carries no score field (since
1375
+ * 0.1.185; before, rows carried `_score`).
1373
1376
  */
1374
- const RELEVANCE_ORDER = {
1375
- stages: [{ $addFields: { [SCORE_FIELD]: { $meta: "textScore" } } }, { $sort: {
1376
- [SCORE_FIELD]: -1,
1377
- _id: 1
1378
- } }],
1379
- cleanup: { $project: { [SCORE_FIELD]: 0 } }
1380
- };
1381
- /** The order of an unranked search (`$rank: false`, since 0.1.175): the primary key. */
1377
+ function relevanceOrder(exact) {
1378
+ const text = { $meta: "textScore" };
1379
+ return {
1380
+ stages: exact.length === 0 ? [{ $addFields: { [SCORE_FIELD]: text } }, { $sort: {
1381
+ [SCORE_FIELD]: -1,
1382
+ _id: 1
1383
+ } }] : [{ $addFields: { [SCORE_FIELD]: {
1384
+ exact: { $or: exact },
1385
+ text
1386
+ } } }, { $sort: {
1387
+ [`${SCORE_FIELD}.exact`]: -1,
1388
+ [`${SCORE_FIELD}.text`]: -1,
1389
+ _id: 1
1390
+ } }],
1391
+ cleanup: { $project: { [SCORE_FIELD]: 0 } }
1392
+ };
1393
+ }
1394
+ /** The order of a search without a text rank (`$rank: false`, since 0.1.175; an integer-only index): the primary key. */
1382
1395
  const UNRANKED_ORDER = { stages: [{ $sort: { _id: 1 } }] };
1383
1396
  /** Vector search via $vectorSearch aggregation stage. */
1384
1397
  async function vectorSearchImpl(host, vector, query, indexName) {
@@ -1517,8 +1530,8 @@ function resolveThreshold(host, controls, indexName) {
1517
1530
  return host.getVectorThreshold(indexName);
1518
1531
  }
1519
1532
  /**
1520
- * Builds the first pipeline stage for a text search and reports whether it is a
1521
- * classic `$text` query (vs. an Atlas `$search`).
1533
+ * Builds the first pipeline stage for a text search and the order of its rows
1534
+ * without a `$sort` (a classic index; an Atlas `$search` keeps its own).
1522
1535
  *
1523
1536
  * Two distinct execution paths share the `search()` API:
1524
1537
  * - **Classic text** (`@db.index.fulltext`, or an adapter-scanned `text`
@@ -1546,12 +1559,12 @@ function buildSearchStage(host, text, indexName, controls) {
1546
1559
  } }));
1547
1560
  if (!hasText) return {
1548
1561
  stage: { $match: equalities.length === 0 ? { _id: { $in: [] } } : equalities.length === 1 ? equalities[0] : { $or: equalities } },
1549
- classicText: false
1562
+ relevance: UNRANKED_ORDER
1550
1563
  };
1551
1564
  const textMatch = { $text: { $search: index.match === "all" ? mongoRequireEveryTerm(text) : text } };
1552
1565
  return {
1553
1566
  stage: { $match: equalities.length > 0 ? { $or: [textMatch, ...equalities] } : textMatch },
1554
- classicText: true
1567
+ relevance: relevanceOrder(keys.map((key) => ({ $eq: [`$${key}`, n] })))
1555
1568
  };
1556
1569
  }
1557
1570
  const searchIndex = index;
@@ -1602,13 +1615,10 @@ function buildSearchStage(host, text, indexName, controls) {
1602
1615
  should: clauses,
1603
1616
  minimumShouldMatch: 1
1604
1617
  } };
1605
- return {
1606
- stage: { $search: {
1607
- index: index.key,
1608
- ...body
1609
- } },
1610
- classicText: false
1611
- };
1618
+ return { stage: { $search: {
1619
+ index: index.key,
1620
+ ...body
1621
+ } } };
1612
1622
  }
1613
1623
  /**
1614
1624
  * Resolves query-time fuzzy (typo tolerance): the `$fuzzy` request control
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { a as buildMongoQuery, c as planStages, f as sortStages, h as queryNodeToExpr, i as buildMongoFilter, l as correlate, m as orNull, n as distinctCountExpr, o as collationOfAdapter, p as exprToMongo, r as REL_FILTER_TEMP_PREFIX, s as mongoFilterStages, t as buildAccumulator, u as hasNullsPlacement } from "./mongo-accumulator-CFVRBDiw.mjs";
1
+ import { a as buildMongoQuery, c as planStages, f as sortStages, h as queryNodeToExpr, i as buildMongoFilter, l as correlate, m as orNull, n as distinctCountExpr, o as collationOfAdapter, p as exprToMongo, r as REL_FILTER_TEMP_PREFIX, s as mongoFilterStages, t as buildAccumulator, u as hasNullsPlacement } from "./mongo-accumulator-BDgJ8wpS.mjs";
2
2
  import { t as dynamicSearchEncryptedMessage } from "./search-messages-mQSpJ4GD.mjs";
3
3
  import { ALL_AGGREGATE_FNS, ALL_BUCKET_UNITS, ALL_VIEW_CAPABILITIES, BaseDbAdapter, DbError, DbSpace, andFilters, bucketTimeZoneUnavailable, computeInsights, constraintViolation, containsRelationFilter, createChangeRecorder, createFailureCollector, defaultFulltextIndex, geoIndexNotFoundMessage, getDbFieldOp, getKeyProps, getPath, isAtscriptDbView, isFieldRef, isPlainObject, isViewType, parseDefaultLiteral, queryReadColumns, relationStaticFilter, resolveDesignType, searchIndexNotFoundMessage, searchTermInteger, storedObjectType, tableNameOf, translateQueryTree, uniqueKeyTuple, unknownWithRelation, vectorIndexNotFoundMessage } from "@atscript/db";
4
4
  import { MongoClient, ObjectId } from "mongodb";
@@ -1330,9 +1330,9 @@ function requireSearchStage(host, text, indexName, controls) {
1330
1330
  * path). `$index` picks the search index by the same rules as `search()`, and
1331
1331
  * an unresolvable one throws exactly as the leaf path does.
1332
1332
  *
1333
- * `classicText` is deliberately dropped: it only drives the leaf runner's
1334
- * relevance order (the `textScore` it sorts by), and no per-document score
1335
- * survives `$group`. See `resolveAggregateSearch` in `@atscript/db/agg` for
1333
+ * The plan's `relevance` order is deliberately dropped: it only orders the
1334
+ * leaf runner's rows, and no per-document score survives `$group`. See
1335
+ * `resolveAggregateSearch` in `@atscript/db/agg` for
1336
1336
  * the normative cross-adapter contract.
1337
1337
  */
1338
1338
  function buildAggregateSearchStage(host, controls) {
@@ -1351,33 +1351,46 @@ async function searchWithCountImpl(host, text, query, indexName) {
1351
1351
  return runSearchWithCountPipeline(host, plan.stage, query, "searchWithCount", textRunOptions(plan, query));
1352
1352
  }
1353
1353
  /**
1354
- * The runner options of a text search: relevance from `textScore` for a
1355
- * classic `$text` match — none under `$rank: false` (since 0.1.175), which
1356
- * orders by `_id` instead (an Atlas `$search` included).
1354
+ * The runner options of a text search: the plan's relevance order — none
1355
+ * under `$rank: false` (since 0.1.175), which orders by `_id` instead (an
1356
+ * Atlas `$search` included).
1357
1357
  */
1358
1358
  function textRunOptions(plan, query) {
1359
1359
  if (query.controls?.$rank === false) return { defaultOrder: UNRANKED_ORDER };
1360
- return plan.classicText ? { defaultOrder: RELEVANCE_ORDER } : {};
1360
+ return { defaultOrder: plan.relevance };
1361
1361
  }
1362
1362
  /**
1363
1363
  * Field a search score rides in through the pipeline: the `vectorSearchScore`
1364
1364
  * (renamed to the public `$score` after fetch — a field name cannot start
1365
- * with `$`) or the `textScore` of a relevance order (dropped from the rows).
1365
+ * with `$`) or the score of a relevance order (dropped from the rows).
1366
1366
  */
1367
1367
  const SCORE_FIELD = "__atscript_score";
1368
1368
  /**
1369
- * Classic `$text` relevance order: `textScore` descending, `_id` breaking ties
1370
- * (since 0.1.165). The score is dropped after `$skip` / `$limit`, so a row
1371
- * carries no score field (since 0.1.185; before, rows carried `_score`).
1369
+ * Classic `$text` relevance order: the rows an integer member matched by
1370
+ * exact number first (`exact`: one `$eq` expression per member of a
1371
+ * whole-number search, since 0.1.186 — as the SQL adapters order them), then
1372
+ * `textScore` descending, `_id` breaking ties (since 0.1.165). The score is
1373
+ * dropped after `$skip` / `$limit`, so a row carries no score field (since
1374
+ * 0.1.185; before, rows carried `_score`).
1372
1375
  */
1373
- const RELEVANCE_ORDER = {
1374
- stages: [{ $addFields: { [SCORE_FIELD]: { $meta: "textScore" } } }, { $sort: {
1375
- [SCORE_FIELD]: -1,
1376
- _id: 1
1377
- } }],
1378
- cleanup: { $project: { [SCORE_FIELD]: 0 } }
1379
- };
1380
- /** The order of an unranked search (`$rank: false`, since 0.1.175): the primary key. */
1376
+ function relevanceOrder(exact) {
1377
+ const text = { $meta: "textScore" };
1378
+ return {
1379
+ stages: exact.length === 0 ? [{ $addFields: { [SCORE_FIELD]: text } }, { $sort: {
1380
+ [SCORE_FIELD]: -1,
1381
+ _id: 1
1382
+ } }] : [{ $addFields: { [SCORE_FIELD]: {
1383
+ exact: { $or: exact },
1384
+ text
1385
+ } } }, { $sort: {
1386
+ [`${SCORE_FIELD}.exact`]: -1,
1387
+ [`${SCORE_FIELD}.text`]: -1,
1388
+ _id: 1
1389
+ } }],
1390
+ cleanup: { $project: { [SCORE_FIELD]: 0 } }
1391
+ };
1392
+ }
1393
+ /** The order of a search without a text rank (`$rank: false`, since 0.1.175; an integer-only index): the primary key. */
1381
1394
  const UNRANKED_ORDER = { stages: [{ $sort: { _id: 1 } }] };
1382
1395
  /** Vector search via $vectorSearch aggregation stage. */
1383
1396
  async function vectorSearchImpl(host, vector, query, indexName) {
@@ -1516,8 +1529,8 @@ function resolveThreshold(host, controls, indexName) {
1516
1529
  return host.getVectorThreshold(indexName);
1517
1530
  }
1518
1531
  /**
1519
- * Builds the first pipeline stage for a text search and reports whether it is a
1520
- * classic `$text` query (vs. an Atlas `$search`).
1532
+ * Builds the first pipeline stage for a text search and the order of its rows
1533
+ * without a `$sort` (a classic index; an Atlas `$search` keeps its own).
1521
1534
  *
1522
1535
  * Two distinct execution paths share the `search()` API:
1523
1536
  * - **Classic text** (`@db.index.fulltext`, or an adapter-scanned `text`
@@ -1545,12 +1558,12 @@ function buildSearchStage(host, text, indexName, controls) {
1545
1558
  } }));
1546
1559
  if (!hasText) return {
1547
1560
  stage: { $match: equalities.length === 0 ? { _id: { $in: [] } } : equalities.length === 1 ? equalities[0] : { $or: equalities } },
1548
- classicText: false
1561
+ relevance: UNRANKED_ORDER
1549
1562
  };
1550
1563
  const textMatch = { $text: { $search: index.match === "all" ? mongoRequireEveryTerm(text) : text } };
1551
1564
  return {
1552
1565
  stage: { $match: equalities.length > 0 ? { $or: [textMatch, ...equalities] } : textMatch },
1553
- classicText: true
1566
+ relevance: relevanceOrder(keys.map((key) => ({ $eq: [`$${key}`, n] })))
1554
1567
  };
1555
1568
  }
1556
1569
  const searchIndex = index;
@@ -1601,13 +1614,10 @@ function buildSearchStage(host, text, indexName, controls) {
1601
1614
  should: clauses,
1602
1615
  minimumShouldMatch: 1
1603
1616
  } };
1604
- return {
1605
- stage: { $search: {
1606
- index: index.key,
1607
- ...body
1608
- } },
1609
- classicText: false
1610
- };
1617
+ return { stage: { $search: {
1618
+ index: index.key,
1619
+ ...body
1620
+ } } };
1611
1621
  }
1612
1622
  /**
1613
1623
  * Resolves query-time fuzzy (typo tolerance): the `$fuzzy` request control
@@ -347,7 +347,7 @@ function placedKey(placement, dir) {
347
347
  */
348
348
  function sortStages(controls) {
349
349
  const { $sort: sort, $nulls: nulls } = controls ?? {};
350
- if (!sort) return { stages: [] };
350
+ if (!sort || Object.keys(sort).length === 0) return { stages: [] };
351
351
  if (!hasNullsPlacement(controls)) return { stages: [{ $sort: sort }] };
352
352
  const flags = {};
353
353
  const drop = {};
@@ -347,7 +347,7 @@ function placedKey(placement, dir) {
347
347
  */
348
348
  function sortStages(controls) {
349
349
  const { $sort: sort, $nulls: nulls } = controls ?? {};
350
- if (!sort) return { stages: [] };
350
+ if (!sort || Object.keys(sort).length === 0) return { stages: [] };
351
351
  if (!hasNullsPlacement(controls)) return { stages: [{ $sort: sort }] };
352
352
  const flags = {};
353
353
  const drop = {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atscript/db-mongo",
3
- "version": "0.1.185",
3
+ "version": "0.1.186",
4
4
  "description": "Mongodb plugin for atscript.",
5
5
  "keywords": [
6
6
  "atscript",
@@ -58,7 +58,7 @@
58
58
  "@atscript/typescript": "^0.2.14",
59
59
  "@uniqu/core": "^0.2.2",
60
60
  "mongodb": "^6.17.0",
61
- "@atscript/db": "^0.1.185"
61
+ "@atscript/db": "^0.1.186"
62
62
  },
63
63
  "scripts": {
64
64
  "build": "vp pack",