Commit 8b3d79e6 authored by Tristan Cavelier's avatar Tristan Cavelier

Removing minified version of complex queries

parent 2cd3489d
/*
* Copyright 2013, Nexedi SA
* Released under the LGPL license.
* http://www.gnu.org/licenses/lgpl.html
*/(function(a){"use strict",Object.defineProperty(a,"ComplexQueries",{configurable:!1,enumerable:!1,writable:!1,value:{}}),Object.defineProperty(a.ComplexQueries,"parse",{configurable:!1,enumerable:!1,writable:!1,value:function(a){function d(a){c+=a+"\n"}function e(a){var b=0,c=-1,d=0,e=0,f=a.offset+1;do{f--,b=0,c=-2,e=f;if(a.src.length<=e)return 19;do{switch(b){case 0:a.src.charCodeAt(f)>=0&&a.src.charCodeAt(f)<=8||a.src.charCodeAt(f)>=10&&a.src.charCodeAt(f)<=31||a.src.charCodeAt(f)==33||a.src.charCodeAt(f)>=35&&a.src.charCodeAt(f)<=39||a.src.charCodeAt(f)>=42&&a.src.charCodeAt(f)<=57||a.src.charCodeAt(f)==59||a.src.charCodeAt(f)>=63&&a.src.charCodeAt(f)<=64||a.src.charCodeAt(f)>=66&&a.src.charCodeAt(f)<=77||a.src.charCodeAt(f)>=80&&a.src.charCodeAt(f)<=254?b=1:a.src.charCodeAt(f)==9?b=2:a.src.charCodeAt(f)==40?b=3:a.src.charCodeAt(f)==41?b=4:a.src.charCodeAt(f)==60||a.src.charCodeAt(f)==62?b=5:a.src.charCodeAt(f)==34?b=11:a.src.charCodeAt(f)==79?b=12:a.src.charCodeAt(f)==32?b=13:a.src.charCodeAt(f)==61?b=14:a.src.charCodeAt(f)==65?b=18:a.src.charCodeAt(f)==78?b=19:b=-1;break;case 1:a.src.charCodeAt(f)>=0&&a.src.charCodeAt(f)<=31||a.src.charCodeAt(f)==33||a.src.charCodeAt(f)>=35&&a.src.charCodeAt(f)<=39||a.src.charCodeAt(f)>=42&&a.src.charCodeAt(f)<=57||a.src.charCodeAt(f)>=59&&a.src.charCodeAt(f)<=254?b=1:a.src.charCodeAt(f)==58?b=6:b=-1,c=10,d=f;break;case 2:a.src.charCodeAt(f)>=0&&a.src.charCodeAt(f)<=31||a.src.charCodeAt(f)==33||a.src.charCodeAt(f)>=35&&a.src.charCodeAt(f)<=39||a.src.charCodeAt(f)>=42&&a.src.charCodeAt(f)<=57||a.src.charCodeAt(f)>=59&&a.src.charCodeAt(f)<=254?b=1:a.src.charCodeAt(f)==58?b=6:b=-1,c=1,d=f;break;case 3:b=-1,c=3,d=f;break;case 4:b=-1,c=4,d=f;break;case 5:a.src.charCodeAt(f)==61?b=14:b=-1,c=11,d=f;break;case 6:b=-1,c=8,d=f;break;case 7:b=-1,c=9,d=f;break;case 8:a.src.charCodeAt(f)>=0&&a.src.charCodeAt(f)<=31||a.src.charCodeAt(f)==33||a.src.charCodeAt(f)>=35&&a.src.charCodeAt(f)<=39||a.src.charCodeAt(f)>=42&&a.src.charCodeAt(f)<=57||a.src.charCodeAt(f)>=59&&a.src.charCodeAt(f)<=254?b=1:a.src.charCodeAt(f)==58?b=6:b=-1,c=6,d=f;break;case 9:a.src.charCodeAt(f)>=0&&a.src.charCodeAt(f)<=31||a.src.charCodeAt(f)==33||a.src.charCodeAt(f)>=35&&a.src.charCodeAt(f)<=39||a.src.charCodeAt(f)>=42&&a.src.charCodeAt(f)<=57||a.src.charCodeAt(f)>=59&&a.src.charCodeAt(f)<=254?b=1:a.src.charCodeAt(f)==58?b=6:b=-1,c=5,d=f;break;case 10:a.src.charCodeAt(f)>=0&&a.src.charCodeAt(f)<=31||a.src.charCodeAt(f)==33||a.src.charCodeAt(f)>=35&&a.src.charCodeAt(f)<=39||a.src.charCodeAt(f)>=42&&a.src.charCodeAt(f)<=57||a.src.charCodeAt(f)>=59&&a.src.charCodeAt(f)<=254?b=1:a.src.charCodeAt(f)==58?b=6:b=-1,c=7,d=f;break;case 11:a.src.charCodeAt(f)==34?b=7:a.src.charCodeAt(f)>=0&&a.src.charCodeAt(f)<=33||a.src.charCodeAt(f)>=35&&a.src.charCodeAt(f)<=91||a.src.charCodeAt(f)>=93&&a.src.charCodeAt(f)<=254?b=11:a.src.charCodeAt(f)==92?b=15:b=-1;break;case 12:a.src.charCodeAt(f)>=0&&a.src.charCodeAt(f)<=31||a.src.charCodeAt(f)==33||a.src.charCodeAt(f)>=35&&a.src.charCodeAt(f)<=39||a.src.charCodeAt(f)>=42&&a.src.charCodeAt(f)<=57||a.src.charCodeAt(f)>=59&&a.src.charCodeAt(f)<=81||a.src.charCodeAt(f)>=83&&a.src.charCodeAt(f)<=254?b=1:a.src.charCodeAt(f)==58?b=6:a.src.charCodeAt(f)==82?b=8:b=-1,c=10,d=f;break;case 13:b=-1,c=1,d=f;break;case 14:b=-1,c=11,d=f;break;case 15:a.src.charCodeAt(f)>=0&&a.src.charCodeAt(f)<=254?b=11:b=-1;break;case 16:a.src.charCodeAt(f)>=0&&a.src.charCodeAt(f)<=31||a.src.charCodeAt(f)==33||a.src.charCodeAt(f)>=35&&a.src.charCodeAt(f)<=39||a.src.charCodeAt(f)>=42&&a.src.charCodeAt(f)<=57||a.src.charCodeAt(f)>=59&&a.src.charCodeAt(f)<=67||a.src.charCodeAt(f)>=69&&a.src.charCodeAt(f)<=254?b=1:a.src.charCodeAt(f)==58?b=6:a.src.charCodeAt(f)==68?b=9:b=-1,c=10,d=f;break;case 17:a.src.charCodeAt(f)>=0&&a.src.charCodeAt(f)<=31||a.src.charCodeAt(f)==33||a.src.charCodeAt(f)>=35&&a.src.charCodeAt(f)<=39||a.src.charCodeAt(f)>=42&&a.src.charCodeAt(f)<=57||a.src.charCodeAt(f)>=59&&a.src.charCodeAt(f)<=83||a.src.charCodeAt(f)>=85&&a.src.charCodeAt(f)<=254?b=1:a.src.charCodeAt(f)==58?b=6:a.src.charCodeAt(f)==84?b=10:b=-1,c=10,d=f;break;case 18:a.src.charCodeAt(f)>=0&&a.src.charCodeAt(f)<=31||a.src.charCodeAt(f)==33||a.src.charCodeAt(f)>=35&&a.src.charCodeAt(f)<=39||a.src.charCodeAt(f)>=42&&a.src.charCodeAt(f)<=57||a.src.charCodeAt(f)>=59&&a.src.charCodeAt(f)<=77||a.src.charCodeAt(f)>=79&&a.src.charCodeAt(f)<=254?b=1:a.src.charCodeAt(f)==58?b=6:a.src.charCodeAt(f)==78?b=16:b=-1,c=10,d=f;break;case 19:a.src.charCodeAt(f)>=0&&a.src.charCodeAt(f)<=31||a.src.charCodeAt(f)==33||a.src.charCodeAt(f)>=35&&a.src.charCodeAt(f)<=39||a.src.charCodeAt(f)>=42&&a.src.charCodeAt(f)<=57||a.src.charCodeAt(f)>=59&&a.src.charCodeAt(f)<=78||a.src.charCodeAt(f)>=80&&a.src.charCodeAt(f)<=254?b=1:a.src.charCodeAt(f)==58?b=6:a.src.charCodeAt(f)==79?b=17:b=-1,c=10,d=f}f++}while(b>-1)}while(c==1);return c>-1?(a.att=a.src.substr(e,d-e),a.offset=d):(a.att=new String,c=-1),c}function f(a,f,g){var l=new Array,m=new Array,n=0,p,q,r,s,t=new Function("","var offset; var src; var att;"),u=new t,v=new Array(new Array(0,1),new Array(13,1),new Array(12,1),new Array(12,2),new Array(12,3),new Array(14,1),new Array(14,3),new Array(15,2),new Array(15,1),new Array(16,3),new Array(16,2),new Array(16,1),new Array(17,2),new Array(17,1),new Array(18,1),new Array(18,1)),w=new Array(new Array(7,5,3,7,8,8,11,10,10,12,9,13),new Array(19,0),new Array(19,-1),new Array(6,14,7,5,3,7,8,8,11,10,10,12,9,13,19,-2,4,-2),new Array(5,16,19,-5,7,-5,3,-5,8,-5,11,-5,10,-5,9,-5,6,-5,4,-5),new Array(3,7,8,8,11,10,10,12,9,13),new Array(19,-8,7,-8,3,-8,8,-8,11,-8,10,-8,9,-8,6,-8,5,-8,4,-8),new Array(7,5,3,7,8,8,11,10,10,12,9,13),new Array(3,7,8,8,11,10,10,12,9,13),new Array(19,-11,7,-11,3,-11,8,-11,11,-11,10,-11,9,-11,6,-11,5,-11,4,-11),new Array(10,12,9,13),new Array(19,-13,7,-13,3,-13,8,-13,11,-13,10,-13,9,-13,6,-13,5,-13,4,-13),new Array(19,-14,7,-14,3,-14,8,-14,11,-14,10,-14,9,-14,6,-14,5,-14,4,-14),new Array(19,-15,7,-15,3,-15,8,-15,11,-15,10,-15,9,-15,6,-15,5,-15,4,-15),new Array(7,5,3,7,8,8,11,10,10,12,9,13),new Array(19,-3,4,-3),new Array(7,5,3,7,8,8,11,10,10,12,9,13),new Array(19,-7,7,-7,3,-7,8,-7,11,-7,10,-7,9,-7,6,-7,5,-7,4,-7),new Array(4,23),new Array(19,-10,7,-10,3,-10,8,-10,11,-10,10,-10,9,-10,6,-10,5,-10,4,-10),new Array(19,-12,7,-12,3,-12,8,-12,11,-12,10,-12,9,-12,6,-12,5,-12,4,-12),new Array(19,-4,4,-4),new Array(19,-6,7,-6,3,-6,8,-6,11,-6,10,-6,9,-6,6,-6,4,-6),new Array(19,-9,7,-9,3,-9,8,-9,11,-9,10,-9,9,-9,6,-9,5,-9,4,-9)),x=new Array(new Array(13,1,12,2,14,3,15,4,16,6,17,9,18,11),new Array,new Array,new Array(12,15,14,3,15,4,16,6,17,9,18,11),new Array,new Array(16,17,17,9,18,11),new Array,new Array(12,18,14,3,15,4,16,6,17,9,18,11),new Array(16,19,17,9,18,11),new Array,new Array(18,20),new Array,new Array,new Array,new Array(12,21,14,3,15,4,16,6,17,9,18,11),new Array,new Array(14,22,15,4,16,6,17,9,18,11),new Array,new Array,new Array,new Array,new Array,new Array,new Array),y=new Array("begin'","WHITESPACE","WHITESPACE","LEFT_PARENTHESE","RIGHT_PARENTHESE","AND","OR","NOT","COLUMN","STRING","WORD","OPERATOR","search_text","begin","and_expression","boolean_expression","expression","value","string","$");u.offset=0,u.src=a,u.att=new String,f||(f=new Array),g||(g=new Array),l.push(0),m.push(0),r=e(u);for(;;){p=25;for(var z=0;z<w[l[l.length-1]].length;z+=2)if(w[l[l.length-1]][z]==r){p=w[l[l.length-1]][z+1];break}b&&l.length>0&&d("\nState "+l[l.length-1]+"\n"+"\tLookahead: "+y[r]+' ("'+u.att+'")\n'+"\tAction: "+p+"\n"+'\tSource: "'+u.src.substr(u.offset,30)+(u.offset+30<u.src.length?"...":"")+'"\n'+"\tStack: "+l.join()+"\n"+"\tValue stack: "+m.join()+"\n");if(p==25){b&&d("Error detected: There is no reduce or shift on the symbol "+y[r]),n++,f.push(u.offset-u.att.length),g.push(new Array);for(var z=0;z<w[l[l.length-1]].length;z+=2)g[g.length-1].push(y[w[l[l.length-1]][z]]);var A=new Array,B=new Array;for(var z=0;z<l.length;z++)A[z]=l[z],B[z]=m[z];while(p==25&&r!=19){b&&d("\tError recovery\nCurrent lookahead: "+y[r]+" ("+u.att+")\n"+"Action: "+p+"\n\n"),r==-1&&u.offset++;while(p==25&&l.length>0){l.pop(),m.pop();if(l.length==0)break;p=25;for(var z=0;z<w[l[l.length-1]].length;z+=2)if(w[l[l.length-1]][z]==r){p=w[l[l.length-1]][z+1];break}}if(p!=25)break;for(var z=0;z<A.length;z++)l.push(A[z]),m.push(B[z]);r=e(u)}if(p==25){b&&d("\tError recovery failed, terminating parse process...");break}b&&d("\tError recovery succeeded, continuing")}if(p>0)b&&d("Shifting symbol: "+y[r]+" ("+u.att+")"),l.push(p),m.push(u.att),r=e(u),b&&d("\tNew lookahead symbol: "+y[r]+" ("+u.att+")");else{p*=-1,b&&d("Reducing by producution: "+p),s=void 0,b&&d("\tPerforming semantic action...");switch(p){case 0:s=m[m.length-1];break;case 1:o=m[m.length-1];break;case 2:s=m[m.length-1];break;case 3:s=j("OR",[m[m.length-2],m[m.length-1]]);break;case 4:s=j("OR",[m[m.length-3],m[m.length-1]]);break;case 5:s=m[m.length-1];break;case 6:s=j("AND",[m[m.length-3],m[m.length-1]]);break;case 7:s=i(m[m.length-1]);break;case 8:s=m[m.length-1];break;case 9:s=m[m.length-2];break;case 10:k(m[m.length-1],m[m.length-2].split(":").slice(0,-1).join(":")),s=m[m.length-1];break;case 11:s=m[m.length-1];break;case 12:m[m.length-1].operator=m[m.length-2],s=m[m.length-1];break;case 13:s=m[m.length-1];break;case 14:s=h("",m[m.length-1]);break;case 15:s=h("",m[m.length-1].split('"').slice(1,-1).join('"'))}b&&d("\tPopping "+v[p][1]+" off the stack...");for(var z=0;z<v[p][1];z++)l.pop(),m.pop();q=-1;for(var z=0;z<x[l[l.length-1]].length;z+=2)if(x[l[l.length-1]][z]==v[p][0]){q=x[l[l.length-1]][z+1];break}if(p==0)break;b&&d("\tPushing non-terminal "+y[v[p][0]]),l.push(q),m.push(s)}b&&(alert(c),c=new String)}return b&&(d("\nParse complete."),alert(c)),n}var b=!1,c=new String,g=function(){var a,b,c=[],d=arguments;for(a=0;a<d.length;++a)for(b=0;b<d[a].length;++b)c.push(d[a][b]);return c},h=function(a,b,c){return{type:"simple",operator:"=",id:a,value:b}},i=function(a){return a.operator==="NOT"?a.query_list[0]:{type:"complex",operator:"NOT",query_list:[a]}},j=function(a,b){var c,d=[];for(c=0;c<b.length;++c)b[c].operator===a?d=g(d,b[c].query_list):d.push(b[c]);return{type:"complex",operator:a,query_list:d}},k=function(a,b){var c;if(a.type==="complex"){for(c=0;c<a.query_list.length;++c)k(a.query_list[c],b);return!0}return a.type==="simple"&&!a.id?(a.id=b,!0):!1},l=[],m=[],n=0,o;if((n=f(a,l,m))>0){var p;for(p=0;p<n;++p)throw new Error('Parse error near "'+a.substr(l[p])+'", expecting "'+m[p].join()+'"')}return o}}),Object.defineProperty(a.ComplexQueries,"serialize",{configurable:!1,enumerable:!1,writable:!1,value:function(b){var c=[],d;if(b.type==="complex"){c.push("(");for(d=0;d<b.query_list.length;++d)c.push(a.ComplexQueries.serialize(b.query_list[d])),c.push(b.operator);return c.length--,c.push(")"),c.join(" ")}return b.type==="simple"?b.id+(b.id?": ":"")+b.operator+' "'+b.value+'"':b}}),Object.defineProperty(a.ComplexQueries,"query",{configurable:!1,enumerable:!1,writable:!1,value:function(b,c){var d=typeof b.wildcard_character=="string"?b.wildcard_character:"%",e={"=":function(a,b){return a=""+a,a.match(f(b,d))||!1},"!=":function(a,b){return a=""+a,!a.match(f(b,d))},"<":function(a,b){return a<b},"<=":function(a,b){return a<=b},">":function(a,b){return a>b},">=":function(a,b){return a>=b},AND:function(a,b){var c;for(c=0;c<b.length;++c)if(!h(a,b[c]))return!1;return!0},OR:function(a,b){var c;for(c=0;c<b.length;++c)if(h(a,b[c]))return!0;return!1},NOT:function(a,b){return!h(a,b[0])}},f=function(a){return g("^"+a.replace(new RegExp("([\\{\\}\\(\\)\\^\\$\\&\\.\\*\\?\\/\\+\\|\\[\\]\\-\\\\])".replace(d?"\\"+d:undefined,""),"g"),"\\$1")+"$",d||undefined,".*")},g=function(a,b,c){var d="",e=0;if(b===undefined)return a;for(;;){var f=a.indexOf(b,e);if(f===-1)break;for(;e<f;++e)d+=a[e];d+=c,e+=b.length}for(;e<a.length;++e)d+=a[e];return d},h=function(a,b){var c;return b.type==="complex"?e[b.operator](a,b.query_list):b.id?typeof a[b.id]!="undefined"?e[b.operator](a[b.id],b.value):!1:!0},i=function(a,b){var c;if(b.length===0)return;for(c=0;c<a.length;++c){var d={},e;for(e=0;e<b.length;++e)d[b[e]]=a[c][b[e]];a[c]=d}},j=function(a,b){return b==="descending"?function(b,c){return b[a]<c[a]?1:b[a]>c[a]?-1:0}:function(b,c){return b[a]>c[a]?1:b[a]<c[a]?-1:0}},k=function(a,b,c){var d,e;for(d=c,e=0;d<b.length+c;++d,++e)a[d]=b[e]},l=function(a,b){var c,d,e,f,g=function(){l(d,b.slice(1)),k(a,d,c-d.length),d=[a[c]]};if(a.length<2)return;if(b.length===0)return;e=b[0][0],f=b[0][1],a.sort(j(e,f)),d=[a[0]];for(c=1;c<a.length;++c)d[0][e]===a[c][e]?d.push(a[c]):g();g()},m=function(a,b){var c;typeof b[0]!="undefined"&&(typeof b[1]!="undefined"?(a.length>b[1]+b[0]&&(a.length=b[1]+b[0]),a.splice(0,b[0])):a.length=b[0])},n=[],o=[],p;c=c||[];for(p=0;p<c.length;++p)h(c[p],a.ComplexQueries.parse(b.query))&&n.push(c[p]);return b.filter&&(i(n,b.filter.select_list||[]),l(n,b.filter.sort_on||[]),m(n,b.filter.limit||[])),n}})})(jIO);
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment