src/main/webapp/js/singlepage-bls.js
/** 
					 * Process a Node. A Field object is always contained within a Node (as far as I can tell).
					 * So for a simple query like 'field:value', the library returns a structure like:
					 * ```
					 * { // Node
					 *   field: 'field',
					 *   left: { // Field
					 *     field: '<implicit>', // referring to property 'field' in the enclosing Node structure
					 *     term: 'value'
					 *    }
					 * }
					 * ```
					 * So if the Node contains a 'field' property we know all children will be Field instances defining the values
					 * and we can open a new context that we can store the values in later parsing steps.
					 * @param {Node} val 
					 */
Process a Node. A Field object is always contained within a Node (as far as I can tell).
Process a Node . A Field object is always contained within a Node ( as far as I can tell ) .
function node(val) {
						if (val == null)
							return;
						var createdContext = false;
						if (val.field) {
							if (context == null && val.field && val.field !== '<implicit>') {
								context = {
									name: val.field,
									filterType: 'select',
									values: []
								};
								createdContext = true;
							} else if (context != null && val.field && val.field !== '<implicit>') {
								if (SINGLEPAGE.DEBUG) {
									console.log('Got a node with a field, but already have context, ignoring.', context);
									debugger;
								}
								return;
							}
						}
						var cur = val.left; 
						if ('left' in cur) node(cur);
						else if ('term' in cur) field(cur);
						else if ('term_min' in cur) range(cur);
						if (val.right && 
							((context == null && !(val.operator === 'OR' || val.operator === '<implicit>')) || 
							(context != null && !(val.operator == 'AND' )))
						) { 
							cur = val.right;
							if ('left' in cur) node(cur);
							else if ('term' in cur) field(cur);
							else if ('term_min' in cur) range(cur);
						}
						if (createdContext) {
							if (context == null) {
								if (SINGLEPAGE.DEBUG) {
									console.log('We started a context but didn\'t end with one, some other function pushed it, that shouldn\'t happen...');
									debugger;
								}
							} else {
								parsedValues.push(context);
								context = null;
							}
						}
					}
function node ( val ) { if ( val == null ) return ; var createdContext = false ; if ( val . field ) { if ( context == null && val . field && val . field !== '<implicit>' ) { context = { name : val . field , filterType : 'select' , values : [ ] } ; createdContext = true ; } else if ( context != null && val . field && val . field !== '<implicit>' ) { if ( SINGLEPAGE . DEBUG ) { console . log ( 'Got a node with a field, but already have context, ignoring.' , context ) ; debugger ; } return ; } } var cur = val . left ; if ( 'left' in cur ) node ( cur ) ; else if ( 'term' in cur ) field ( cur ) ; else if ( 'term_min' in cur ) range ( cur ) ; if ( val . right && ( ( context == null && ! ( val . operator === 'OR' || val . operator === '<implicit>' ) ) || ( context != null && ! ( val . operator == 'AND' ) ) ) ) { cur = val . right ; if ( 'left' in cur ) node ( cur ) ; else if ( 'term' in cur ) field ( cur ) ; else if ( 'term_min' in cur ) range ( cur ) ; } if ( createdContext ) { if ( context == null ) { if ( SINGLEPAGE . DEBUG ) { console . log ( 'We started a context but didn\'t end with one, some other function pushed it, that shouldn\'t happen...' ) ; debugger ; } } else { parsedValues . push ( context ) ; context = null ; } } }
Process a Node.
Process a Node .
// if there is no context yet, the field can still be <implicit>, in this case we'd expect that the left node // defines the field name, this is the case with range expression, so we will define the context when processing the left node. // this is weird, and it should probably never happen // it would mean we're going to define terms for a field while we're already inside the term list expression for another field // left always present /**
						 * We need to know what the right side contains if we're to handle it.
						 * - If have a context, that means both left and right are values for a specific field (or Nodes containg a subtree of multiple values).
						 * The current Node is the OR/AND token in a query like 'field:("value" OR "value2")'
						 * The interface can only handle OR'ing all values for a field, so check that the query doesn't specify AND,
						 * and if it does then skip processing the right side of the tree. 
						 * - If we _don't_ have a context, then left and right define the Fields themselves 
						 * The current Node is then the OR/AND token in a query like 'field1:value1 AND field2:value2'
						 * In thise case, the interface can only handle AND'ing all the different fields, so check that too.
						 */ // implicit operator between field means OR // else we're already inside inside an existing context and are just recursing over the values