|
| 1 | +/* @flow */ |
| 2 | + |
| 3 | +import { InputTypeComposer } from 'graphql-compose'; |
| 4 | +import { getQueryITC } from '../Query'; |
| 5 | +import { getTypeName, getOrSetType, desc } from "../../../utils"; |
| 6 | + |
| 7 | +export function getFunctionScoreITC(opts: mixed = {}): InputTypeComposer { |
| 8 | + const name = getTypeName('QueryFunctionScore', opts); |
| 9 | + const description = desc(` |
| 10 | + The function_score allows you to modify the score of documents that |
| 11 | + are retrieved by a query. This can be useful if, for example, |
| 12 | + a score function is computationally expensive and it is sufficient |
| 13 | + to compute the score on a filtered set of documents. |
| 14 | + [Documentation](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html) |
| 15 | + `); |
| 16 | + |
| 17 | + // $FlowFixMe |
| 18 | + const RandomScoreType = InputTypeComposer.create({ |
| 19 | + name: getTypeName('QueryFunctionScoreRandom', opts), |
| 20 | + fields: { |
| 21 | + seed: 'Float', |
| 22 | + }, |
| 23 | + }); |
| 24 | + |
| 25 | + return getOrSetType(name, () => |
| 26 | + // $FlowFixMe |
| 27 | + InputTypeComposer.create({ |
| 28 | + name, |
| 29 | + description, |
| 30 | + fields: { |
| 31 | + query: () => getQueryITC(opts), |
| 32 | + boost: 'String', |
| 33 | + boost_mode: { |
| 34 | + type: 'String', |
| 35 | + description: 'Can be: `multiply`, `replace`, `sum`, `avg`, `max`, `min`.', |
| 36 | + }, |
| 37 | + random_score: RandomScoreType, |
| 38 | + // $FlowFixMe |
| 39 | + functions: [InputTypeComposer.create({ |
| 40 | + name: getTypeName('QueryFunctionScoreFunction', opts), |
| 41 | + fields: { |
| 42 | + filter: () => getQueryITC(opts), |
| 43 | + random_score: RandomScoreType, |
| 44 | + weight: 'Float', |
| 45 | + script_score: 'JSON', |
| 46 | + field_value_factor: 'JSON', |
| 47 | + gauss: 'JSON', |
| 48 | + linear: 'JSON', |
| 49 | + exp: 'JSON', |
| 50 | + }, |
| 51 | + })], |
| 52 | + max_boost: 'Float', |
| 53 | + score_mode: { |
| 54 | + type: 'String', |
| 55 | + description: 'Can be: `multiply`, `sum`, `avg`, `first`, `max`, `min`.', |
| 56 | + }, |
| 57 | + min_score: 'Float', |
| 58 | + }, |
| 59 | + }) |
| 60 | + ); |
| 61 | +} |
0 commit comments