I'm writing a very powerful search engine.. the boolean operators are not actual words but are easy to remember...
QAND,QOR,QNOT... My problem is this, the search query is pretty heavy, so I want to limit the number of words / phrases to 5 and pop up an alert if the number is greater than 5...
word QAND phrase QAND idea QNOT microsoft would pass word QAND MS QOR Micro QNOT Site QAND Cool QOR Wow would not pass...
I know how the script needs to be written just don't know how to write it...
The boolean operators will only work surrounded with a space on each side.. so what I need the JS to do (Netscape AND IE compatibility here) is replace each boolean operator with a comma (,) or whatever... The $ appears nowhere in the Bible which is my search base so that would be a good delimiter.. Anyway it needs to make a list of it and then ListLen() it.. If JS does not have a listlen function, what that is, is it counts the number of elements in a list (at least in cold fusion)... If the number is greater than 5, alert, and then abort the form submit, if not, go on...
Any help very greatly appreciated,
I'm not exactly sure what you need by the above as most of what you mentioned should be done behind the scenes with a server side language ie php, jsp, asp etc.
As for counting the length of an array it is extremely simple.
myArray = new Array();
myArray[i++] = '0';
myArray[i++] = '1';
myArray[i++] = '2';
myArray[i++] = '3';
myArray[i++] = '4';
myArray[i++] = '5';
myArray[i++] = '6';
myArray[i++] = '7';
myArray[i++] = '8';
myArray[i++] = '9';
Ok.. could do it server side but JS will handle it client side and save my server some processing time.. Maybe if I write it in CF, you'll grok my needs...
// Setting the search variable here, but it would actually come from a text field...
<CFSET sVar="God said QAND Jesus QOR Messiah QNOT Satan QOR Michael QAND the angel">
(The syntax of the Replace/ReplaceNoCase Fuctions... are (String, Substring1, Substring2, ONE[Replace first instance]/ALL[Replace all instances]))
<CFSET sVar=ReplaceNoCase(svar," QAND " , "," , "ALL")>
<CFSET sVar=ReplaceNoCase(svar," QOR " , "," , "ALL")>
<CFSET sVar=ReplaceNoCase(svar," QNOT " , "," , "ALL")>
<CFIF ListLen(sVar) gt 5>
Error! Error! To many words or phrases.
Process Search Query
Does this help?
There is no real link between server-side scripting language and client-side scripting language - they are separate and distinct, serving two completely different purposes, and should be chosen independently on their separate merits (since there are no joint merits to consider - any combination can be made to work together).
Very True... but for isntance with CF, if you are working with variabes and you want to display a pound sign, you have to double it ##.. And then it displays as a single on a webpage..
There are things to consider here :)
it may be hard because your not used to it or you have made the code unclear in the first place. Anyway i'm not too sure about cf but that kind of problem you seem to have come accross is very rare,
The closest problem you may have to that is escaping characters. But thats in most languages anyway.
Erk, never came across it.. not yet, but all I was saying is that each language can counteract with JS in some way..
it's not even that tho. Theres clientside and theres server side, now a language that does come close to or does in effect combine clientside to the serverside is asp.net and as far as im aware no other language does.