tosenzzz / trimpath

Automatically exported from code.google.com/p/trimpath
0 stars 0 forks source link

query fix to multiple LIKE, case insensitive, etc #31

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
This release of trimpath core (trimpath query + trimpath JST + extras)
contains 3 mods:

      mod 1: added 'i' for case insensitive
      mod 2: changed S to [a-zA-Z0-9 %^$]+
          mod 3: multiple LIKEs

Here is the code,  but I attach trimpath core and minified version so you
can drop in.  In the future core may include the faster JST version that
was circulating in the forums.  Would also lump in some small utilities.

           var js = this.sql;
            js = js.replace(/ AND /g, " && ");
            js = js.replace(/ OR /g, " || ");
            js = js.replace(/ = /g, " == ");
            js = js.replace(/ IS NULL/g, " == null");
            js = js.replace(/ IS NOT NULL/g, " != null");
            js = js.replace(/ NOT /g, " ! ");

            var LIKE_regex = /(\S+)\sLIKE\s'([a-zA-Z0-9 %^$]+)'/g;
            var LIKE_regex_incr = /(\S+)\sLIKE\s'([a-zA-Z0-9 %^$]+)'/;
            var matchArr;
            while(matchArr = LIKE_regex.exec(js) ) {
                matchArr[2] = matchArr[2].replace(/%/, '.*');
                js = js.replace(LIKE_regex_incr,
"$1.match(/"+matchArr[2]+"/i)");
            }

Original issue reported on code.google.com by kucerari...@gmail.com on 9 Oct 2009 at 3:28

Attachments:

GoogleCodeExporter commented 8 years ago
actually debugged this issue on the Try It Yourself editor for match()

http://www.w3schools.com/jsref/jsref_match_regexp.asp

Original comment by kucerari...@gmail.com on 9 Oct 2009 at 3:30

GoogleCodeExporter commented 8 years ago
fixed an issue with allowable characters for keyword searches.

on your input boxes way up at the front end,  please filter,  it is the best 
place to
do it:

    keywords[i] = keywords[i].replace(/[^a-zA-Z0-9 %^$.]/g, '.');

That regex needs to work in conjunction with the regex in trimpath core,  this 
is a
best compromise for keywords as far as I know.  Added '.' in order to replace
unacceptable characters with single wildcard.  In practice I think this is 
acceptable:

           var js = this.sql;
            js = js.replace(/ AND /g, " && ");
            js = js.replace(/ OR /g, " || ");
            js = js.replace(/ = /g, " == ");
            js = js.replace(/ IS NULL/g, " == null");
            js = js.replace(/ IS NOT NULL/g, " != null");
            js = js.replace(/ NOT /g, " ! ");

            var LIKE_regex = /(\S+)\sLIKE\s'([a-zA-Z0-9 %^$.]+)'/g;
            var LIKE_regex_incr = /(\S+)\sLIKE\s'([a-zA-Z0-9 %^$.]+)'/;
            var matchArr;
            while(matchArr = LIKE_regex.exec(js) ) {
                matchArr[2] = matchArr[2].replace(/%/, '.*');
                js = js.replace(LIKE_regex_incr, "$1.match(/"+matchArr[2]+"/i)");
            }

There are new attachments with this code.

Original comment by kucerari...@gmail.com on 13 Oct 2009 at 3:02

Attachments: