mirror of https://github.com/apache/lucene.git
Initial commit of javascript lucene query validator.
This is the version from http://marc.theaimsgroup.com/?l=lucene-user&m=101964415222254&w=2. I'm so glad its finally been rescued from the depths of mailing list archives! git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@150761 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
01bb49e1a4
commit
f6c9d225a1
|
@ -0,0 +1,60 @@
|
|||
//
|
||||
// JavaScript Lucene Query Validator
|
||||
// Author: Kelvin Tan (kelvin@relevanz.com)
|
||||
// Date: 10/04/2002
|
||||
|
||||
// validates a lucene query.
|
||||
// @param Form field that contains the query
|
||||
function doCheckLuceneQuery(queryField)
|
||||
{
|
||||
var query = queryField.value;
|
||||
if(query != null && query.length > 0)
|
||||
{
|
||||
var matches = query.match(/^(\*)|([^a-zA-Z0-9_]\*)/);
|
||||
|
||||
// check wildcards are used properly
|
||||
if(matches != null && matches.length > 0)
|
||||
{
|
||||
alert("Invalid search query! The wildcard (*) character must be preceded by at least one alphabet or number. Please try again.")
|
||||
return false;
|
||||
}
|
||||
|
||||
// check parentheses are used properly
|
||||
matches = query.match(/^([^\n()]*|(\(([a-zA-Z0-9_+\-:()\" ]|\*)+\)))*$/);
|
||||
if(matches == null || matches.length == 0)
|
||||
{
|
||||
alert("Invalid search query! Parentheses must contain at least one alphabet or number. Please try again.")
|
||||
return false;
|
||||
}
|
||||
|
||||
// check '+' and '-' are used properly
|
||||
matches = query.match(/^(([^\n+-]*|[+-]([a-zA-Z0-9_:()]|\*)+))*$/);
|
||||
if(matches == null || matches.length == 0)
|
||||
{
|
||||
alert("Invalid search query! '+' and '-' modifiers must be followed by at least one alphabet or number. Please try again.")
|
||||
return false;
|
||||
}
|
||||
|
||||
// check that quote marks are closed
|
||||
matches = query.match(/\"/g);
|
||||
if(matches != null)
|
||||
{
|
||||
var number = matches.length;
|
||||
if((number % 2) > 0)
|
||||
{
|
||||
alert("Invalid search query! Please close all quote (\") marks.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// check ':' is used properly
|
||||
matches = query.match(/^(([^\n:]*|([a-zA-Z0-9_]|\*)+[:]([a-zA-Z0-9_()"]|\*)+))*$/);
|
||||
if(matches == null || matches.length == 0)
|
||||
{
|
||||
alert("Invalid search query! Field declarations (:) must be preceded by at least one alphabet or number and followed by at least one alphabet or number. Please try again.")
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue