// Lucene Search Query Constructor // Author: Kelvin Tan (kelvint at apache.org) // Change this according to what you use to name the field modifiers in your form. // e.g. with the field "name", the modifier will be called "nameModifier" var modifierSuffix = 'Modifier'; // Do you wish the query to be displayed as an alert box? var debug = false; // Do you wish the function to submit the form upon query construction? var submitOnConstruction = false; // prefix modifier for boolean AND queries var AND_MODIFIER = '+'; // prefix modifier for boolean NOT queries var NOT_MODIFIER = '-'; // prefix modifier for boolean OR queries var OR_MODIFIER = ''; // default prefix modifier for boolean queries var DEFAULT_MODIFIER = OR_MODIFIER; // used to delimit multiple values from checkboxes and select lists var VALUE_DELIMITER = ' '; // Constructs the query // @param query Form field to represent the constructed query to be submitted // @param debug Turn on debugging? function doMakeQuery( query, dbg ) { if(typeof(dbg) != "undefined") debug = dbg; var frm = query.form; var formElements = frm.elements; query.value = ''; // keep track of the fields we've examined var dict = new Array(); for(var i=0; i 0 && elementValue != ' ') { var subElement = frm[elementName + modifierSuffix]; if(typeof(subElement) != "undefined") // found a field/fieldModifier pair { // assume that the user only allows one logic, i.e. AND OR, AND NOT, OR NOT, etc not supported var logic = getFieldValue(subElement); if(logic == 'And') { addFieldWithModifier(query, AND_MODIFIER, elementName, elementValue); } else if(logic == 'Not') { addFieldWithModifier(query, NOT_MODIFIER, elementName, elementValue); } else if(logic == 'Or') { addFieldWithModifier(query, OR_MODIFIER, elementName, elementValue); } else { addFieldWithModifier(query, DEFAULT_MODIFIER, elementName, elementValue); } } } } } if(debug) { alert('Query:' + query.value); } if(submitOnConstruction) { frm.submit(); } } function contains(array, s) { for(var i=0; i