UNPKG

@azure/cosmos

Version:
71 lines (70 loc) 2.61 kB
var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var GlobalStatisticsAggregator_exports = {}; __export(GlobalStatisticsAggregator_exports, { GlobalStatisticsAggregator: () => GlobalStatisticsAggregator }); module.exports = __toCommonJS(GlobalStatisticsAggregator_exports); class GlobalStatisticsAggregator { globalStatistics; constructor() { this.globalStatistics = { documentCount: 0, fullTextStatistics: [] }; } aggregate(other) { if (!other) { return; } this.globalStatistics.documentCount += other.documentCount; if (!other.fullTextStatistics || other.fullTextStatistics.length === 0) { return; } if (this.globalStatistics.fullTextStatistics.length === 0) { this.globalStatistics.fullTextStatistics = other.fullTextStatistics.map((stat) => ({ totalWordCount: stat.totalWordCount, hitCounts: [...stat.hitCounts] })); } else { for (let i = 0; i < other.fullTextStatistics.length; i++) { const otherStat = other.fullTextStatistics[i]; if (!this.globalStatistics.fullTextStatistics[i]) { this.globalStatistics.fullTextStatistics[i] = { totalWordCount: 0, hitCounts: [] }; } this.globalStatistics.fullTextStatistics[i].totalWordCount += otherStat.totalWordCount; for (let j = 0; j < otherStat.hitCounts.length; j++) { if (this.globalStatistics.fullTextStatistics[i].hitCounts.length <= j) { this.globalStatistics.fullTextStatistics[i].hitCounts.push(0); } this.globalStatistics.fullTextStatistics[i].hitCounts[j] += otherStat.hitCounts[j]; } } } } getResult() { return this.globalStatistics; } } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { GlobalStatisticsAggregator });