From 8c1b134a7ae9f1a16e9791e77c339187ad0eeb63 Mon Sep 17 00:00:00 2001 From: Erik Hatcher Date: Fri, 23 Jan 2004 16:59:38 +0000 Subject: [PATCH] enhanced sample, but validator is acting up it seems. kelvin - am i doing something wrong? git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@150938 13f79535-47bb-0310-9956-ffa450edef68 --- .../luceneQueryConstructor.html | 58 ++++++++++++++++--- .../luceneQueryConstructor.js | 35 +++++------ 2 files changed, 67 insertions(+), 26 deletions(-) diff --git a/sandbox/contributions/javascript/queryConstructor/luceneQueryConstructor.html b/sandbox/contributions/javascript/queryConstructor/luceneQueryConstructor.html index 573aa559948..9916c4623b9 100644 --- a/sandbox/contributions/javascript/queryConstructor/luceneQueryConstructor.html +++ b/sandbox/contributions/javascript/queryConstructor/luceneQueryConstructor.html @@ -2,27 +2,67 @@ Demo Lucene Query Constructor + - +
+

Name: +

+

Description: - + + + + +

+ +

+ Required Select: + + +

+ +

+ Multi-select: + + +

+ +

+ Radio: + + WNRN + KLPX + +

+ +

+ Current Query: +


+      

+ + +
\ No newline at end of file diff --git a/sandbox/contributions/javascript/queryConstructor/luceneQueryConstructor.js b/sandbox/contributions/javascript/queryConstructor/luceneQueryConstructor.js index 28144a88eb0..9922009d1a7 100644 --- a/sandbox/contributions/javascript/queryConstructor/luceneQueryConstructor.js +++ b/sandbox/contributions/javascript/queryConstructor/luceneQueryConstructor.js @@ -33,14 +33,14 @@ 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) + var elementValue = trim(getFieldValue(frm[element.name])); + + if(elementValue.length > 0 && elementValue != ' ') { var subElement = frm[elementName + modifierSuffix]; if(typeof(subElement) != "undefined") // found a field/fieldModifier pair @@ -62,7 +63,7 @@ function doMakeQuery( query, dbg ) if(logic == 'And') { addFieldWithModifier(query, AND_MODIFIER, elementName, elementValue); - } + } else if(logic == 'Not') { addFieldWithModifier(query, NOT_MODIFIER, elementName, elementValue); @@ -79,12 +80,12 @@ function doMakeQuery( query, dbg ) } } } - + if(debug) { alert('Query:' + query.value); } - + if(submitOnConstruction) { frm.submit(); @@ -107,9 +108,9 @@ function getFieldValue(field) return getCheckedValues(field); if(typeof(field[0]) != "undefined" && field[0].type=="radio") return getRadioValue(field); - if(field.type.match("select*")) + if(field.type.match("select*")) return getSelectedValues(field); - + return field.value; } @@ -146,7 +147,7 @@ function getSelectedValues (select) { function addFieldWithModifier(query, modifier, field, fieldValue) { fieldValue = trim(fieldValue); - + if(query.value.length == 0) { query.value = modifier + '(' + field + ':(' + fieldValue + '))'; @@ -154,19 +155,19 @@ function addFieldWithModifier(query, modifier, field, fieldValue) else { query.value = query.value + ' ' + modifier + '(' + field + ':(' + fieldValue + '))'; - } + } } function trim(inputString) { if (typeof inputString != "string") { return inputString; } - + var temp = inputString; - + // Replace whitespace with a single space var pattern = /\s+/ig; temp = temp.replace(pattern, " "); - - // Trim + + // Trim pattern = /^(\s*)([\w\W]*)(\b\s*$)/; if (pattern.test(temp)) { temp = temp.replace(pattern, "$2"); } return temp; // Return the trimmed string back to the user