UNPKG

@klevu/core

Version:

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

37 lines (36 loc) 1.49 kB
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()); }); }; /** * Boost or deboost query based on a keywords. * * @category Modifier * @param keywords Keywords to boost and deboost * @returns KlevuModifier that be used to modify query */ export function boostWithKeywords(keywords) { return { klevuModifierId: "boostWithKeywords", 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.keywords) { q.boost.keywords = keywords; } else { q.boost.keywords.push(...keywords); } } return copy; }), }; }