mirror of https://github.com/apache/lucene.git
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
This commit is contained in:
parent
9b57a1288f
commit
b84ac2fb26
|
@ -1,7 +1,5 @@
|
||||||
// Lucene Search Query Constructor
|
// Lucene Search Query Constructor
|
||||||
// Author: Kelvin Tan (kelvin@relevanz.com)
|
// 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.
|
// 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"
|
// 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?
|
// Do you wish the function to submit the form upon query construction?
|
||||||
var submitOnConstruction = true;
|
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
|
// Constructs the query
|
||||||
// @param query Form field to represent the constructed query to be submitted
|
// @param query Form field to represent the constructed query to be submitted
|
||||||
function doMakeQuery( query )
|
function doMakeQuery( query )
|
||||||
|
@ -35,15 +45,19 @@ function doMakeQuery( query )
|
||||||
var subElementValue = subElement.options[subElement.selectedIndex].value;
|
var subElementValue = subElement.options[subElement.selectedIndex].value;
|
||||||
if(subElementValue == 'And')
|
if(subElementValue == 'And')
|
||||||
{
|
{
|
||||||
addAnd(query, elementName, elementValue);
|
addFieldWithModifier(query, AND_MODIFIER, elementName, elementValue);
|
||||||
}
|
}
|
||||||
else if(subElementValue == 'Not')
|
else if(subElementValue == 'Not')
|
||||||
{
|
{
|
||||||
addNot(query, elementName, elementValue);
|
addFieldWithModifier(query, NOT_MODIFIER, elementName, elementValue);
|
||||||
}
|
}
|
||||||
else if(subElementValue == 'Or')
|
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)
|
if(query.value.length == 0)
|
||||||
{
|
{
|
||||||
query.value = '(' + field + ':(' + fieldValue + '))';
|
query.value = modifier + '(' + field + ':(' + fieldValue + '))';
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
query.value = query.value + ' (' + field + ':(' + fieldValue + '))';
|
query.value = query.value + ' ' + modifier + '(' + 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 + '))';
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue