@webiny/api-headless-cms-ddb-es
Version:
DynamoDB and Elasticsearch storage operations plugin for Headless CMS API.
34 lines (31 loc) • 935 B
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.assignMinimumShouldMatchToQuery = void 0;
/**
* This function will assign a minimum_should_match for the query if conditions are met:
* * should is an array
* * it is not empty
* * minimum_should_match is not already set
*
*
* By the default we set it to 1 as we want at least one OR condition to produce results.
*
* Users can modify minimum_should_match value via the body or query modification plugins.
*/
const assignMinimumShouldMatchToQuery = ({
query,
value = 1
}) => {
if (!Array.isArray(query.should)) {
return;
} else if (query.should.length === 0) {
return;
} else if (query.minimum_should_match) {
return;
}
query.minimum_should_match = value > 0 ? value : 1;
};
exports.assignMinimumShouldMatchToQuery = assignMinimumShouldMatchToQuery;
//# sourceMappingURL=assignMinimumShouldMatchToQuery.js.map