From b84ac2fb265c7e81ff250da2ca5d058067986ca7 Mon Sep 17 00:00:00 2001 From: Kelvin Tan Date: Thu, 9 May 2002 02:39:26 +0000 Subject: [PATCH] Merged the various add* methods into a single method. Added constants for AND, NOT and OR prefix modifiers. Added a default modifier. git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@150763 13f79535-47bb-0310-9956-ffa450edef68 --- .../luceneQueryConstructor.js | 54 ++++++++----------- 1 file changed, 22 insertions(+), 32 deletions(-) diff --git a/sandbox/contributions/javascript/queryConstructor/luceneQueryConstructor.js b/sandbox/contributions/javascript/queryConstructor/luceneQueryConstructor.js index 229eb84baae..99bc283dc2b 100644 --- a/sandbox/contributions/javascript/queryConstructor/luceneQueryConstructor.js +++ b/sandbox/contributions/javascript/queryConstructor/luceneQueryConstructor.js @@ -1,7 +1,5 @@ // Lucene Search Query Constructor // Author: Kelvin Tan (kelvin@relevanz.com) -// Date: 14/02/2002 -// Version: 1.1 // 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" @@ -13,6 +11,18 @@ var debug = true; // Do you wish the function to submit the form upon query construction? var submitOnConstruction = true; +// 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; + // Constructs the query // @param query Form field to represent the constructed query to be submitted function doMakeQuery( query ) @@ -35,15 +45,19 @@ function doMakeQuery( query ) var subElementValue = subElement.options[subElement.selectedIndex].value; if(subElementValue == 'And') { - addAnd(query, elementName, elementValue); + addFieldWithModifier(query, AND_MODIFIER, elementName, elementValue); } else if(subElementValue == 'Not') { - addNot(query, elementName, elementValue); + addFieldWithModifier(query, NOT_MODIFIER, elementName, elementValue); } else if(subElementValue == 'Or') { - addOr(query, elementName, elementValue); + addFieldWithModifier(query, OR_MODIFIER, elementName, elementValue); + } + else + { + addFieldWithModifier(query, DEFAULT_MODIFIER, elementName, elementValue); } } } @@ -61,38 +75,14 @@ function doMakeQuery( query ) } } -function addOr(query, field, fieldValue) +function addFieldWithModifier(query, modifier, field, fieldValue) { if(query.value.length == 0) { - query.value = '(' + field + ':(' + fieldValue + '))'; + query.value = modifier + '(' + field + ':(' + fieldValue + '))'; } else { - query.value = query.value + ' (' + field + ':(' + fieldValue + '))'; - } -} - -function addAnd(query, field, fieldValue) -{ - if(query.value.length == 0) - { - query.value = '+(' + field + ':(' + fieldValue + '))'; - } - else - { - query.value = query.value + ' +(' + field + ':(' + fieldValue + '))'; - } -} - -function addNot(query, field, fieldValue) -{ - if(query.value.length == 0) - { - query.value = '-(' + field + ':(' + fieldValue + '))'; - } - else - { - query.value = query.value + ' -(' + field + ':(' + fieldValue + '))'; + query.value = query.value + ' ' + modifier + '(' + field + ':(' + fieldValue + '))'; } } \ No newline at end of file