@@ -248,7 +248,7 @@ const index = {
248248 return str . match ( / ^ ( ( [ ^ < > ( ) \[ \] \\ . , ; : \s @ " ] + ( \. [ ^ < > ( ) \[ \] \\ . , ; : \s @ " ] + ) * ) | ( " .+ " ) ) @ ( ( \[ [ 0 - 9 ] { 1 , 3 } \. [ 0 - 9 ] { 1 , 3 } \. [ 0 - 9 ] { 1 , 3 } \. [ 0 - 9 ] { 1 , 3 } ] ) | ( ( [ a - z A - Z \- 0 - 9 ] + \. ) + [ a - z A - Z ] { 2 , } ) ) $ / ) ;
249249 } ,
250250
251- filterBuilder ( q = [ ] )
251+ filterBuilder ( q = [ ] , doc = 'doc' )
252252 {
253253 const filtersSchema = joi . array ( ) . required ( ) . items ( joi . object ( {
254254 key : joi . string ( ) . required ( ) ,
@@ -257,7 +257,8 @@ const index = {
257257 } ) ) ;
258258
259259 const validation = filtersSchema . validate ( q ) ;
260- if ( validation . error ) {
260+ if ( validation . error )
261+ {
261262 throw validation . error ;
262263 }
263264
@@ -273,26 +274,34 @@ const index = {
273274 for ( let i = 0 ; i < q . length ; i ++ )
274275 {
275276 const el = q [ i ] ;
277+ const key = `${ doc } ${ el . key . split ( '.' ) . map ( k => `.${ k } ` ) . join ( '' ) } ` ;
278+
276279 switch ( el . op )
277280 {
278281 case '~' :
279- parts . push ( aql ` doc[${ el . key } ] != ${ el . value } ` ) ;
282+ parts . push ( aql . literal ( key ) ) ;
283+ parts . push ( aql ` != ${ el . value } ` ) ;
280284 break ;
281285
282286 case '>' :
283- parts . push ( aql `(doc[${ el . key } ] > ${ el . value } )` ) ;
287+ parts . push ( aql . literal ( key ) ) ;
288+ parts . push ( aql ` > ${ el . value } ` ) ;
284289 break ;
285290
286291 case '<' :
287- parts . push ( aql ` doc[${ el . key } ] < ${ el . value } ` ) ;
292+ parts . push ( aql . literal ( key ) ) ;
293+ parts . push ( aql ` < ${ el . value } ` ) ;
288294 break ;
289295
290296 case '%' :
291- parts . push ( aql `LIKE(doc[${ el . key } ], ${ el . value } , true)` ) ;
297+ //parts.push(aql.literal('LIKE('));
298+ parts . push ( aql . literal ( `LIKE(${ key } ,` ) ) ;
299+ parts . push ( aql `${ el . value } , true)` ) ;
292300 break ;
293301
294302 default :
295- parts . push ( aql `(doc[${ el . key } ] == ${ el . value } )` ) ;
303+ parts . push ( aql . literal ( key ) ) ;
304+ parts . push ( aql ` == ${ el . value } ` ) ;
296305 break ;
297306 }
298307
0 commit comments