UNPKG

@azure/cosmos

Version:
68 lines (67 loc) 2.31 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 hybridSearchQueryResult_exports = {}; __export(hybridSearchQueryResult_exports, { HybridSearchQueryResult: () => HybridSearchQueryResult }); module.exports = __toCommonJS(hybridSearchQueryResult_exports); const FieldNames = { Rid: "_rid", Payload: "payload", ComponentScores: "componentScores" }; class HybridSearchQueryResult { rid; componentScores; data; score; ranks; constructor(rid, componentScores, data) { this.rid = rid; this.componentScores = componentScores; this.data = data; } static create(document) { const rid = document[FieldNames.Rid]; if (!rid) { throw new Error(`${FieldNames.Rid} must exist.`); } const outerPayload = document[FieldNames.Payload]; let componentScores; let data; if (!outerPayload || typeof outerPayload !== "object") { throw new Error(`${FieldNames.Payload} must exist.`); } const innerPayload = outerPayload[FieldNames.Payload]; if (innerPayload && typeof innerPayload === "object") { componentScores = outerPayload[FieldNames.ComponentScores]; data = innerPayload; } else { componentScores = document[FieldNames.ComponentScores]; data = outerPayload; } if (!Array.isArray(componentScores)) { throw new Error(`${FieldNames.ComponentScores} must exist.`); } return new HybridSearchQueryResult(rid, componentScores, data); } } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { HybridSearchQueryResult });