UNPKG

@klevu/core

Version:

Typescript SDK that simplifies development on Klevu backend. Klevu provides advanced AI-powered search and discovery solutions for online retailers.

41 lines (40 loc) 1.63 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.boostWithRecords = void 0; /** * Boost or deboost query based on a record ids. * * @category Modifier * @param records Keywords to boost and deboost * @returns KlevuModifier that be used to modify query */ function boostWithRecords(records) { return { klevuModifierId: "boostWithRecords", modifyAfter: (queries) => __awaiter(this, void 0, void 0, function* () { const copy = Array.from(queries); for (const q of queries) { if (!q.boost) { q.boost = {}; } if (!q.boost.records) { q.boost.records = records; } else { q.boost.records.push(...records); } } return copy; }), }; } exports.boostWithRecords = boostWithRecords;