diff --git a/sandbox/contributions/javascript/queryConstructor/luceneQueryConstructor.js b/sandbox/contributions/javascript/queryConstructor/luceneQueryConstructor.js index b0948ca6402..28144a88eb0 100644 --- a/sandbox/contributions/javascript/queryConstructor/luceneQueryConstructor.js +++ b/sandbox/contributions/javascript/queryConstructor/luceneQueryConstructor.js @@ -1,5 +1,5 @@ // Lucene Search Query Constructor -// Author: Kelvin Tan (kelvin at relevanz.com) +// 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" @@ -23,59 +23,51 @@ 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 -function doMakeQuery( query ) +// @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) + if(!contains(dict, elementName)) { - for(var j=0; j 0) { - var subElement = formElements[j]; - if(subElement.name == (elementName + modifierSuffix)) + var subElement = frm[elementName + modifierSuffix]; + if(typeof(subElement) != "undefined") // found a field/fieldModifier pair { - var subElementValue; - - // support drop-down select lists, radio buttons and text fields - if(subElement.type == "select") - { - subElementValue = subElement.options[subElement.selectedIndex].value; - } - else if(subElement.type == "radio") - { - // radio button elements often have the same element name, - // so ensure we have the right one - if(subElement.checked) - { - subElementValue = subElement.value; - } - else - { - continue; - } - } - else - { - subElementValue = subElement.value; - } - - if(subElementValue == 'And') + // 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(subElementValue == 'Not') + else if(logic == 'Not') { addFieldWithModifier(query, NOT_MODIFIER, elementName, elementValue); } - else if(subElementValue == 'Or') + else if(logic == 'Or') { addFieldWithModifier(query, OR_MODIFIER, elementName, elementValue); } @@ -99,6 +91,58 @@ function doMakeQuery( query ) } } +function contains(array, s) +{ + for(var i=0; i