function CreateAnd (Expression1,Expression2) { CombinedExpression = ""; CombinedExpression = CombinedExpression + '(AND'; if (Expression1.indexOf('(')!=-1) { CombinedExpression = CombinedExpression + ' ' + Expression1; } else { if (Expression1.indexOf('"')!=-1) { CombinedExpression = CombinedExpression + ' (TOKEN ' + Expression1 + ')'; } else { if (IncludesWild(Expression1)) { CombinedExpression = CombinedExpression + ' (TOKEN:WILD "' + Expression1 + '")'; } else { CombinedExpression = CombinedExpression + ' (TOKEN "' + Expression1 + '")'; } } } if (Expression2.indexOf('(')!=-1) { CombinedExpression = CombinedExpression + ' ' + Expression2; } else { if (Expression2.indexOf('"')!=-1) { CombinedExpression = CombinedExpression + ' (TOKEN ' + Expression2 + ')'; } else { if (IncludesWild(Expression2)) { CombinedExpression = CombinedExpression + ' (TOKEN:WILD "' + Expression2 + '")'; } else { CombinedExpression = CombinedExpression + ' (TOKEN "' + Expression2 + '")'; } } } CombinedExpression = CombinedExpression + ' )'; return CombinedExpression; } //This function takes two expressions and produces a GQL OR //statement. //Standard text is included in TOKEN statements - with the //WILD suffix if it contains wildcard characters. //Phrases are included in PHRASE statments. //Expressions that begin with a bracket are allowed to pass //through as these have already been processed. function CreateOr (Expression1,Expression2) { CombinedExpression = ""; CombinedExpression = CombinedExpression + '(OR'; if (Expression1.indexOf('(')!=-1) { CombinedExpression = CombinedExpression + ' ' + Expression1; } else { if (Expression1.indexOf('"')!=-1) { CombinedExpression = CombinedExpression + ' (TOKEN ' + Expression1 + ')'; } else { if (IncludesWild(Expression1)) { CombinedExpression = CombinedExpression + ' (TOKEN:WILD "' + Expression1 + '")'; } else { CombinedExpression = CombinedExpression + ' (TOKEN "' + Expression1 + '")'; } } } if (Expression2.indexOf('(')!=-1) { CombinedExpression = CombinedExpression + ' ' + Expression2; } else { if (Expression2.indexOf('"')!=-1) { CombinedExpression = CombinedExpression + ' (TOKEN ' + Expression2 + ')'; } else { if (IncludesWild(Expression2)) { CombinedExpression = CombinedExpression + ' (TOKEN:WILD "' + Expression2 + '")'; } else { CombinedExpression = CombinedExpression + ' (TOKEN "' + Expression2 + '")'; } } } CombinedExpression = CombinedExpression + ' )'; return CombinedExpression; } //This function takes two expressions and produces a GQL //SUBTRACT statement. //Standard text is included in TOKEN statements - with the //WILD suffix if it contains wildcard characters. //Phrases are included in PHRASE statments. //Expressions that begin with a bracket are allowed to pass //through as these have already been processed. function CreateNot (Expression1,Expression2) { CombinedExpression = ""; CombinedExpression = CombinedExpression + '(SUBTRACT'; if (Expression1.indexOf('(')!=-1) { CombinedExpression = CombinedExpression + ' ' + Expression1; } else { if (Expression1.indexOf('"')!=-1) { CombinedExpression = CombinedExpression + ' (TOKEN ' + Expression1 + ')'; } else { if (IncludesWild(Expression1)) { CombinedExpression = CombinedExpression + ' (TOKEN:WILD "' + Expression1 + '")'; } else { CombinedExpression = CombinedExpression + ' (TOKEN "' + Expression1 + '")'; } } } if (Expression2.indexOf('(')!=-1) { CombinedExpression = CombinedExpression + ' ' + Expression2; } else { if (Expression2.indexOf('"')!=-1) { CombinedExpression = CombinedExpression + ' (TOKEN ' + Expression2 + ')'; } else { if (IncludesWild(Expression2)) { CombinedExpression = CombinedExpression + ' (TOKEN:WILD "' + Expression2 + '")'; } else { CombinedExpression = CombinedExpression + ' (TOKEN "' + Expression2 + '")'; } } } CombinedExpression = CombinedExpression + ' )'; return CombinedExpression; } function IncludesWild (Expression) { WildChars = false; if ((Expression.indexOf("*")!=-1)|(Expression.indexOf("?")!=-1)) { WildChars = true; } return WildChars; } function trim(inputString) { var retValue = inputString; var ch = retValue.substring(0, 1); while (ch == " ") { // Check for spaces at the beginning of the string retValue = retValue.substring(1, retValue.length); ch = retValue.substring(0, 1); } ch = retValue.substring(retValue.length-1, retValue.length); while (ch == " ") { // Check for spaces at the end of the string retValue = retValue.substring(0, retValue.length-1); ch = retValue.substring(retValue.length-1, retValue.length); } while (retValue.indexOf(" ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string retValue = retValue.substring(0, retValue.indexOf(" ")) + retValue.substring(retValue.indexOf(" ")+1, retValue.length); // Again, there are two spaces in each of the strings } return retValue; // Return the trimmed string back to the user } function Translate(Expression) { Expression = trim(Expression); NewExpression = ""; ElementsCount = 0; Elements = new Array(); Elements[ElementsCount] = ""; BracketLevel = 0; for (i=0;i0) { Elements[ElementsCount] = Elements[ElementsCount] + ElementChar; i++; if (i==Expression.length) { BracketLevel=0; } else { ElementChar = Expression.charAt(i); if (ElementChar=='(') { BracketLevel++; }else if (ElementChar==')') { BracketLevel--; } } } Elements[ElementsCount] = Elements[ElementsCount] + ")"; }else if (ElementChar=='"') { Elements[ElementsCount] = Elements[ElementsCount] + '"'; i++; ElementChar = Expression.charAt(i); while (ElementChar!='"') { Elements[ElementsCount] = Elements[ElementsCount] + ElementChar; i++; if (i>=Expression.length) { ElementChar = '"'; } else { ElementChar = Expression.charAt(i); } } Elements[ElementsCount] = Elements[ElementsCount] + '"'; }else if (ElementChar==" ") { ElementsCount++; Elements[ElementsCount] = ""; } else { Elements[ElementsCount] = Elements[ElementsCount] + ElementChar; } } for (i=0;i<=ElementsCount;i++) { //alert(Elements[i]); } //alert(ElementsCount); if (ElementsCount==0) { if (Elements[0].indexOf('(')!=-1) { NewExpression = Elements[0]; } else { if (Elements[0].indexOf('"')!=-1) { NewExpression = '(TOKEN ' + Elements[0] + ')'; } else { if (IncludesWild(Elements[0])) { NewExpression = '(TOKEN:WILD "' + Elements[0] + '")'; } else { NewExpression = '(TOKEN "' + Elements[0] + '")'; } } } } else if (ElementsCount==1) { NewExpression = NewExpression + '(AND'; for (i=0;i<=ElementsCount;i++) { if (Elements[i].indexOf('(')!=-1) { NewExpression = NewExpression + ' ' + Elements[i]; } else { if (Elements[i].indexOf('"')!=-1) { NewExpression = NewExpression + ' (TOKEN ' + Elements[i] + ')'; } else { if (IncludesWild(Elements[i])) { NewExpression = NewExpression + ' (TOKEN:WILD "' + Elements[i] + '")'; } else { NewExpression = NewExpression + ' (TOKEN "' + Elements[i] + '")'; } } } } NewExpression = NewExpression + ' )'; } else { AndRe = /and/i; OrRe = /or/i; NotRe = /not/i; FoundOperator = false; for (i=0;i<=ElementsCount;i++) { if((Elements[i].toLowerCase()=="and")|(Elements[i].toLowerCase()=="or")|(Elements[i].toLowerCase()=="not")) { FoundOperator = true; } } if (FoundOperator==false) { NewExpression = NewExpression + '(AND '; for (i=0;i<=ElementsCount;i++) { if (Elements[i].indexOf('(')!=-1) { NewExpression = NewExpression + ' ' + Elements[i]; } else { if (Elements[i].indexOf('"')!=-1) { NewExpression = NewExpression + ' (TOKEN ' + Elements[i] + ')'; } else { if (IncludesWild(Elements[i])) { NewExpression = NewExpression + ' (TOKEN:WILD "' + Elements[i] + '")'; } else { NewExpression = NewExpression + ' (TOKEN "' + Elements[i] + '")'; } } } } NewExpression = NewExpression + ' )'; } else { for (i=0;i=1;e--) { StartIndex = SearchString.indexOf("OB"+e); EndIndex = SearchString.indexOf("CB"+e); StringToProcess = SearchString.substring(StartIndex+2+String(e).length,EndIndex); //alert(StringToProcess); TranslatedString = Translate(StringToProcess); //alert(TranslatedString); NewSearchString = ""; for (c=0;c0;l--) { NewExpression = NewExpression + "CB" + OpenBrackets[l]; } return NewExpression; } //----------------------- function TranslateToGQL(SearchString) { if (SearchString.indexOf("(")!=-1) { SearchString = CalculateBrackets(SearchString); SearchString = TranslateByBrackets(SearchString); } else { SearchString = Translate(SearchString); } return SearchString; } //----------------------- function CreateGQL() { if (document.forms[1].SimpleQueryString.value != "") { GQLQueryString = TranslateToGQL(document.forms[1].SimpleQueryString.value); } else { GQLQueryString = ""; } DispQueryString = "" + document.forms[1].SimpleQueryString.value + " "; }