Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add query plan optimization
  • Loading branch information
amanrao23 committed May 5, 2025
commit 953f83c49f106cf95fe7a05ad28e008a6f91a211
19 changes: 13 additions & 6 deletions sdk/cosmosdb/cosmos/src/request/hybridSearchQueryResult.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,27 @@ export class HybridSearchQueryResult {
}

const outerPayload = document[FieldNames.Payload];
let componentScores: number[];
let data: Record<string, unknown>;

if (!outerPayload || typeof outerPayload !== "object") {
throw new Error(`${FieldNames.Payload} must exist.`);
}

const innerPayload = outerPayload[FieldNames.Payload];
if (!innerPayload || typeof innerPayload !== "object") {
throw new Error(`${FieldNames.Payload} must exist nested within the outer payload field.`);
}

const componentScores = outerPayload[FieldNames.ComponentScores];
if (innerPayload && typeof innerPayload === "object") {
// older format without query plan optimization
componentScores = outerPayload[FieldNames.ComponentScores];
data = innerPayload;
} else {
// newer format with the optimization
componentScores = document[FieldNames.ComponentScores];
data = outerPayload;
}
if (!Array.isArray(componentScores)) {
throw new Error(`${FieldNames.ComponentScores} must exist.`);
}

return new HybridSearchQueryResult(rid, componentScores, innerPayload);
return new HybridSearchQueryResult(rid, componentScores, data);
}
}