mirror of https://github.com/apache/lucene.git
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
This commit is contained in:
parent
5320408426
commit
8c1b134a7a
|
@ -2,27 +2,67 @@
|
|||
<head>
|
||||
<title>Demo Lucene Query Constructor</title>
|
||||
<script type="text/javascript" src="luceneQueryConstructor.js"></script>
|
||||
<script type="text/javascript" src="../queryValidator/luceneQueryValidator.js"></script>
|
||||
</head>
|
||||
|
||||
|
||||
<body>
|
||||
<form>
|
||||
<p>
|
||||
<input type="hidden" name="query">
|
||||
Name:
|
||||
<input type="text" name="name">
|
||||
<select name="nameModifier">
|
||||
<option value="And" />And
|
||||
<option value="Or" selected/>Or
|
||||
<option value="Not" />Not
|
||||
<option value="And">And</option>
|
||||
<option value="Or" selected="selected">Or</option>
|
||||
<option value="Not">Not</option>
|
||||
</select>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
Description:
|
||||
<input type="text" name="description">
|
||||
<select name="descriptionModifier">
|
||||
<option value="And" />And
|
||||
<option value="Or" selected/>Or
|
||||
<option value="Not" />Not
|
||||
</select>
|
||||
<input type="button" name="Search" value="Search" onClick="doMakeQuery(this.form.query)" />
|
||||
<option value="And">And</option>
|
||||
<option value="Or" selected="selected">Or</option>
|
||||
<option value="Not">Not</option>
|
||||
</select>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
Required Select:
|
||||
<select name="choice">
|
||||
<option value="one">One</option>
|
||||
<option value="two">Two</option>
|
||||
</select>
|
||||
<input type="hidden" name="choiceModifier" value="And"/>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
Multi-select:
|
||||
<select name="multi" multiple="true" size="5">
|
||||
<option value="multi1">multi1</option>
|
||||
<option value="multi2">multi2</option>
|
||||
<option value="multi3">multi3</option>
|
||||
<option value="multi4">multi4</option>
|
||||
</select>
|
||||
<input type="hidden" name="multiModifier" value="Or"/>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
Radio:
|
||||
<!-- TODO: something fishy happens if none selected -->
|
||||
<input type="radio" name="radio" value="wnrn" checked="checked" />WNRN
|
||||
<input type="radio" name="radio" value="klpx" />KLPX
|
||||
<input type="hidden" name="radioModifier" value="And"/>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
Current Query:
|
||||
<pre id="curQuery"></pre>
|
||||
</p>
|
||||
|
||||
<input type="button" name="Update" value="Update Query" onClick="doMakeQuery(this.form.query); curQuery.innerText = this.form.query.value" />
|
||||
<input type="button" name="Validate" value="Validate" onClick="doCheckLuceneQuery(this.form.query);" />
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
|
@ -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<formElements.length; i++)
|
||||
{
|
||||
var element = formElements[i];
|
||||
|
@ -48,10 +48,11 @@ function doMakeQuery( query, dbg )
|
|||
if(!contains(dict, elementName))
|
||||
{
|
||||
dict[dict.length] = elementName;
|
||||
|
||||
|
||||
// ensure we get the whole group (of checkboxes, radio, etc), if applicable
|
||||
var elementValue = getFieldValue(frm[element.name]);
|
||||
if(elementValue.length > 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
|
||||
|
|
Loading…
Reference in New Issue