@webiny/api-headless-cms-ddb
Version:
DynamoDB storage operations plugin for Headless CMS API.
50 lines (48 loc) • 1.43 kB
JavaScript
;
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.createFullTextSearch = void 0;
var _error = _interopRequireDefault(require("@webiny/error"));
var _getValue = require("./getValue");
/**
* Unfortunately we must use the contains plugin directly as plugins do not support multi field searching.
*/
const createFullTextSearch = params => {
const {
term,
targetFields,
fields: fieldDefinitions,
plugin
} = params;
if (!term || term.trim().length === 0 || !targetFields || targetFields.length === 0) {
return null;
}
return item => {
for (const target of targetFields) {
/**
* As fields is a mapped Field objects where key is a path to the value, we can directly find the related field.
*/
const field = fieldDefinitions[target];
if (!field) {
throw new _error.default(`Unknown field "${target}" in the model.`, "UNKNOWN_FIELD", {
target
});
}
const value = (0, _getValue.getValue)(item.values, target);
if (!value) {
continue;
}
if (plugin.matches({
value,
compareValue: term
}) === true) {
return true;
}
}
return false;
};
};
exports.createFullTextSearch = createFullTextSearch;
//# sourceMappingURL=fullTextSearch.js.map