UNPKG

981 BJavaScriptView Raw
1
2module.exports = function( subview ){
3 return function( vs ){
4
5 // query section reduces the number of records which
6 // the decay function is applied to.
7 // we simply re-use the another view for the function query.
8 if( !subview ){ return null; } // subview validation failed
9
10 // validate required params
11 if( !vs.isset('popularity:field') ||
12 !vs.isset('popularity:modifier') ||
13 !vs.isset('popularity:max_boost') ){
14 return null;
15 }
16
17 // base view
18 var view = {
19 function_score: {
20 query: subview( vs ),
21 max_boost: vs.var('popularity:max_boost'),
22 functions: [],
23 score_mode: 'first',
24 boost_mode: 'replace'
25 }
26 };
27
28 view.function_score.functions.push({
29 field_value_factor: {
30 modifier: vs.var('popularity:modifier'),
31 field: vs.var('popularity:field'),
32 missing: 1
33 },
34 weight: vs.var('popularity:weight')
35 });
36
37 return view;
38 };
39};