Mailing List Archive

cvs commit: jakarta-lucene-sandbox/contributions/javascript/queryConstructor luceneQueryConstructor.js
kelvint 2002/12/03 03:48:17

Modified: contributions/javascript/queryConstructor
luceneQueryConstructor.js
Log:
Supports radio buttons and text fields as modifiers, instead of boring old select lists.

Revision Changes Path
1.3 +28 -4 jakarta-lucene-sandbox/contributions/javascript/queryConstructor/luceneQueryConstructor.js

Index: luceneQueryConstructor.js
===================================================================
RCS file: /home/cvs/jakarta-lucene-sandbox/contributions/javascript/queryConstructor/luceneQueryConstructor.js,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- luceneQueryConstructor.js 9 May 2002 02:39:26 -0000 1.2
+++ luceneQueryConstructor.js 3 Dec 2002 11:48:17 -0000 1.3
@@ -1,15 +1,15 @@
// Lucene Search Query Constructor
-// Author: Kelvin Tan (kelvin@relevanz.com)
+// Author: Kelvin Tan (kelvin at relevanz.com)

// 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 = true;
+var debug = false;

// Do you wish the function to submit the form upon query construction?
-var submitOnConstruction = true;
+var submitOnConstruction = false;

// prefix modifier for boolean AND queries
var AND_MODIFIER = '+';
@@ -42,7 +42,31 @@
var subElement = formElements[j];
if(subElement.name == (elementName + modifierSuffix))
{
- var subElementValue = subElement.options[subElement.selectedIndex].value;
+ 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')
{
addFieldWithModifier(query, AND_MODIFIER, elementName, elementValue);




--
To unsubscribe, e-mail: <mailto:lucene-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:lucene-dev-help@jakarta.apache.org>
cvs commit: jakarta-lucene-sandbox/contributions/javascript/queryConstructor luceneQueryConstructor.js [ In reply to ]
kelvint 2002/12/04 16:21:45

Modified: contributions/javascript/queryConstructor
luceneQueryConstructor.js
Log:
Trims field values to address any validation problems with whitespace.

Revision Changes Path
1.4 +18 -1 jakarta-lucene-sandbox/contributions/javascript/queryConstructor/luceneQueryConstructor.js

Index: luceneQueryConstructor.js
===================================================================
RCS file: /home/cvs/jakarta-lucene-sandbox/contributions/javascript/queryConstructor/luceneQueryConstructor.js,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- luceneQueryConstructor.js 3 Dec 2002 11:48:17 -0000 1.3
+++ luceneQueryConstructor.js 5 Dec 2002 00:21:45 -0000 1.4
@@ -52,7 +52,7 @@
else if(subElement.type == "radio")
{
// radio button elements often have the same element name,
- // so ensure we have the right one
+ // so ensure we have the right one
if(subElement.checked)
{
subElementValue = subElement.value;
@@ -101,6 +101,8 @@

function addFieldWithModifier(query, modifier, field, fieldValue)
{
+ fieldValue = trim(fieldValue);
+
if(query.value.length == 0)
{
query.value = modifier + '(' + field + ':(' + fieldValue + '))';
@@ -109,4 +111,19 @@
{
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
+ 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
}




--
To unsubscribe, e-mail: <mailto:lucene-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:lucene-dev-help@jakarta.apache.org>
cvs commit: jakarta-lucene-sandbox/contributions/javascript/queryConstructor luceneQueryConstructor.js [ In reply to ]
kelvint 2002/12/10 19:29:05

Modified: contributions/javascript/queryConstructor
luceneQueryConstructor.js
Log:
Whitespace within the query string wasn't getting gobbled up.

Revision Changes Path
1.5 +1 -1 jakarta-lucene-sandbox/contributions/javascript/queryConstructor/luceneQueryConstructor.js

Index: luceneQueryConstructor.js
===================================================================
RCS file: /home/cvs/jakarta-lucene-sandbox/contributions/javascript/queryConstructor/luceneQueryConstructor.js,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- luceneQueryConstructor.js 5 Dec 2002 00:21:45 -0000 1.4
+++ luceneQueryConstructor.js 11 Dec 2002 03:29:05 -0000 1.5
@@ -119,7 +119,7 @@
var temp = inputString;

// Replace whitespace with a single space
- var pattern = /\s/ig;
+ var pattern = /\s+/ig;
temp = temp.replace(pattern, " ");

// Trim




--
To unsubscribe, e-mail: <mailto:lucene-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:lucene-dev-help@jakarta.apache.org>