UNPKG

1.54 kBJavaScriptView Raw
1/**
2 this view is wrapped in a function so it can be re-used
3**/
4
5var multi_match = require('./multi_match');
6
7/*
8 * Match several admin fields against the same query
9 */
10module.exports = function( admin_properties, analyzer ){
11 return function( vs ){
12
13 // check which of the possible admin_properties are actually set
14 // from the query
15 var valid_admin_properties = admin_properties.filter(function(admin_property) {
16 return admin_property &&
17 vs.isset('input:'+admin_property) &&
18 vs.isset('admin:'+admin_property+':field');
19 });
20
21 if (valid_admin_properties.length === 0) {
22 return null;
23 }
24
25 // from the input parameters, generate a list of fields with boosts to
26 // query against
27 var fields_with_boosts = valid_admin_properties.map(function(admin_property) {
28 var boost = 1;
29 if (vs.isset('admin:' + admin_property + ':boost')) {
30 boost = vs.var('admin:' + admin_property + ':boost');
31 }
32
33 return {
34 field: vs.var('admin:' + admin_property + ':field'),
35 boost: boost
36 };
37 });
38
39 // the actual query text is simply taken from the first valid admin field
40 // this assumes all the values would be the same, which is probably not true
41 // TODO: handle the case where not all admin area input values are the same
42 var queryVar = 'input:' + valid_admin_properties[0];
43
44 // send the parameters to the standard multi_match view
45 var view = multi_match(vs, fields_with_boosts, analyzer, queryVar);
46
47 return view;
48 };
49};