|
2 | 2 |
|
3 | 3 | import { InputTypeComposer } from 'graphql-compose';
|
4 | 4 | import { getQueryITC } from './Query';
|
5 |
| -import { getTypeName, getOrSetType } from "../../utils"; |
| 5 | +import { getTypeName, getOrSetType, desc } from "../../utils"; |
6 | 6 |
|
7 |
| -export function getBoolITC(opts = {}): InputTypeComposer { |
8 |
| - const typeName = getTypeName('QueryBool', opts); |
| 7 | +export function getBoolITC(opts: mixed = {}): InputTypeComposer { |
| 8 | + const name = getTypeName('QueryBool', opts); |
| 9 | + const description = desc(` |
| 10 | + A query that matches documents matching boolean combinations |
| 11 | + of other queries. The bool query maps to Lucene BooleanQuery. |
| 12 | + It is built using one or more boolean clauses, each clause |
| 13 | + with a typed occurrence. |
| 14 | + `); |
9 | 15 |
|
10 |
| - return getOrSetType(typeName, () => { |
11 |
| - const BoolITC = InputTypeComposer.create(typeName); |
12 |
| - BoolITC.setDescription('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. '); |
13 |
| - BoolITC.setFields({ |
14 |
| - must: { |
15 |
| - type: () => getQueryITC(opts), |
16 |
| - description: 'The clause (query) must appear in matching documents and will contribute to the score.', |
| 16 | + return getOrSetType(name, () => |
| 17 | + // $FlowFixMe |
| 18 | + InputTypeComposer.create({ |
| 19 | + name, |
| 20 | + description, |
| 21 | + fields: { |
| 22 | + must: { |
| 23 | + type: () => getQueryITC(opts), |
| 24 | + description: desc(` |
| 25 | + The clause (query) must appear in matching documents |
| 26 | + and will contribute to the score. |
| 27 | + `), |
| 28 | + }, |
| 29 | + filter: { |
| 30 | + type: () => getQueryITC(opts), |
| 31 | + description: desc(` |
| 32 | + The clause (query) must appear in matching documents. |
| 33 | + However unlike must the score of the query will be ignored. |
| 34 | + Filter clauses are executed in filter context, meaning |
| 35 | + that scoring is ignored and clauses are considered for caching. |
| 36 | + `), |
| 37 | + }, |
| 38 | + should: { |
| 39 | + type: () => getQueryITC(opts), |
| 40 | + description: desc(` |
| 41 | + The clause (query) should appear in the matching document. |
| 42 | + In a boolean query with no must or filter clauses, |
| 43 | + one or more should clauses must match a document. |
| 44 | + The minimum number of should clauses to match can be set |
| 45 | + using the minimum_should_match parameter. |
| 46 | + `), |
| 47 | + }, |
| 48 | + minimum_should_match: { |
| 49 | + type: 'Int', |
| 50 | + description: desc(` |
| 51 | + The minimum number of should clauses to match can be set using |
| 52 | + the minimum_should_match parameter. |
| 53 | + `), |
| 54 | + }, |
| 55 | + must_not: { |
| 56 | + type: () => getQueryITC(opts), |
| 57 | + description: desc(` |
| 58 | + The clause (query) must not appear in the matching documents. |
| 59 | + Clauses are executed in filter context meaning that scoring |
| 60 | + is ignored and clauses are considered for caching. |
| 61 | + Because scoring is ignored, a score of 0 for all documents |
| 62 | + is returned. |
| 63 | + `), |
| 64 | + }, |
| 65 | + boost: { |
| 66 | + type: 'Float', |
| 67 | + }, |
17 | 68 | },
|
18 |
| - filter: { |
19 |
| - type: () => getQueryITC(opts), |
20 |
| - description: '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.', |
21 |
| - }, |
22 |
| - should: { |
23 |
| - type: () => getQueryITC(opts), |
24 |
| - description: '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.', |
25 |
| - }, |
26 |
| - minimum_should_match: { |
27 |
| - type: 'Int', |
28 |
| - description: 'The minimum number of should clauses to match can be set using the minimum_should_match parameter.', |
29 |
| - }, |
30 |
| - must_not: { |
31 |
| - type: () => getQueryITC(opts), |
32 |
| - description: '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.', |
33 |
| - }, |
34 |
| - boost: { |
35 |
| - type: 'Float', |
36 |
| - }, |
37 |
| - }); |
38 |
| - |
39 |
| - return BoolITC; |
40 |
| - }); |
| 69 | + }) |
| 70 | + ); |
41 | 71 | }
|
0 commit comments