UNPKG

graphql-compose-elasticsearch

Version:
88 lines 3.52 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.prepareBoolInResolve = exports.getBoolITC = void 0; const Query_1 = require("../Query"); const utils_1 = require("../../../utils"); function getBoolITC(opts) { const name = (0, utils_1.getTypeName)('QueryBool', opts); const description = (0, utils_1.desc)(` A query that matches documents matching boolean combinations of other queries. The bool query maps to Lucene BooleanQuery. It is built using one or more boolean clauses, each clause with a typed occurrence. [Documentation](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-bool-query.html) `); return opts.getOrCreateITC(name, () => ({ name, description, fields: { must: { type: () => [(0, Query_1.getQueryITC)(opts)], description: (0, utils_1.desc)(` The clause (query) must appear in matching documents and will contribute to the score. `), }, filter: { type: () => [(0, Query_1.getQueryITC)(opts)], description: (0, utils_1.desc)(` The clause (query) must appear in matching documents. However unlike must the score of the query will be ignored. Filter clauses are executed in filter context, meaning that scoring is ignored and clauses are considered for caching. `), }, should: { type: () => [(0, Query_1.getQueryITC)(opts)], description: (0, utils_1.desc)(` The clause (query) should appear in the matching document. In a boolean query with no must or filter clauses, one or more should clauses must match a document. The minimum number of should clauses to match can be set using the minimum_should_match parameter. `), }, minimum_should_match: { type: 'String', description: (0, utils_1.desc)(` The minimum number of should clauses to match. `), }, must_not: { type: () => [(0, Query_1.getQueryITC)(opts)], description: (0, utils_1.desc)(` The clause (query) must not appear in the matching documents. Clauses are executed in filter context meaning that scoring is ignored and clauses are considered for caching. Because scoring is ignored, a score of 0 for all documents is returned. `), }, boost: 'Float', }, })); } exports.getBoolITC = getBoolITC; function prepareQueryMayBeArray(vals, fieldMap) { if (Array.isArray(vals)) { return vals.map((val) => (0, Query_1.prepareQueryInResolve)(val, fieldMap)); } return (0, Query_1.prepareQueryInResolve)(vals, fieldMap); } function prepareBoolInResolve(bool, fieldMap) { if (bool.must) { bool.must = prepareQueryMayBeArray(bool.must, fieldMap); } if (bool.filter) { bool.filter = prepareQueryMayBeArray(bool.filter, fieldMap); } if (bool.should) { bool.should = prepareQueryMayBeArray(bool.should, fieldMap); } if (bool.must_not) { bool.must_not = prepareQueryMayBeArray(bool.must_not, fieldMap); } return bool; } exports.prepareBoolInResolve = prepareBoolInResolve; //# sourceMappingURL=Bool.js.map