UNPKG

1.25 kBJavaScriptView Raw
1/***
2 * // simple view for an arbitrary multi_match query
3 *
4 * params:
5 * @fields_with_boosts: objects with a structure like
6 * {
7 * field: 'fieldName',
8 * boost: 5 //optional
9 * }
10 * @analyzer: a string for the analyzer name
11 * @query_var: the variable that stores the actual query
12 *
13 */
14module.exports = function( vs, fields_with_boosts, analyzer, query_var ){
15 // base view
16 var view = { multi_match: {} };
17
18 if (!vs.isset(query_var) || !analyzer) {
19 return null;
20 }
21
22 // construct the field string (which contains the boost)
23 // from the more friendly object representation
24 var fields = fields_with_boosts.map(function(data) {
25 var fieldString = data.field;
26 var boost = data.boost || 1;
27 return fieldString +'^' + boost;
28 });
29
30 view.multi_match.fields = fields;
31 view.multi_match.query = vs.var(query_var);
32 view.multi_match.analyzer = analyzer;
33
34 if (vs.isset('multi_match:type')) {
35 view.multi_match.type = vs.var('multi_match:type');
36 }
37
38 if (vs.isset('multi_match:operator')) {
39 view.multi_match.operator = vs.var('multi_match:operator');
40 }
41
42 if (vs.isset('multi_match:cutoff_frequency')) {
43 view.multi_match.cutoff_frequency = vs.var('multi_match:cutoff_frequency');
44 }
45
46 return view;
47};