@@ -377,11 +377,6 @@ export default class PostgresProposalDataSource implements ProposalDataSource {
377377 return query ;
378378 }
379379
380- safeEscapeRegexExpression ( expression : string ) : string {
381- const escaped = expression . replace ( / [ . * + ? ^ $ { } ( ) | [ \] \\ ] / g, '\\$&' ) ;
382-
383- return escaped ;
384- }
385380 async getProposalsFromView (
386381 filter ?: ProposalsFilter ,
387382 first ?: number ,
@@ -442,10 +437,6 @@ export default class PostgresProposalDataSource implements ProposalDataSource {
442437 searchText !== null &&
443438 searchText !== undefined
444439 ) {
445- const regexLiteral = this . safeEscapeRegexExpression ( searchText ) ;
446- // NOTE: Using jsonpath we check the jsonb (instruments) field if it contains object with name equal to searchText case insensitive
447- const jsonPathPattern = `$[*] ? (@.name.type() == "string" && @.name like_regex "${ regexLiteral } " flag "i")` ;
448-
449440 query . andWhere ( ( qb ) =>
450441 qb
451442 . orWhereRaw ( 'proposal_id ILIKE ?' , [ `%${ searchText } %` ] )
@@ -455,9 +446,11 @@ export default class PostgresProposalDataSource implements ProposalDataSource {
455446 . orWhere ( 'users.firstname' , 'ilike' , `%${ searchText } %` )
456447 . orWhere ( 'users.lastname' , 'ilike' , `%${ searchText } %` )
457448 . orWhere ( 'principal_investigator' , 'in' , principalInvestigator )
458- . orWhereRaw ( 'jsonb_path_exists(instruments, ?)' , [
459- jsonPathPattern ,
460- ] )
449+ . orWhereJsonFieldLikeEscaped (
450+ 'instruments' ,
451+ 'name' ,
452+ `${ searchText } `
453+ )
461454 ) ;
462455 }
463456
@@ -634,10 +627,10 @@ export default class PostgresProposalDataSource implements ProposalDataSource {
634627 . orWhereRaw ( 'users.email ILIKE ?' , `%${ filter . text } %` )
635628 . orWhereRaw ( 'users.firstname ILIKE ?' , `%${ filter . text } %` )
636629 . orWhereRaw ( 'users.lastname ILIKE ?' , `%${ filter . text } %` )
637- // NOTE: Using jsonpath we check the jsonb (instruments) field if it contains object with name equal to searchText case insensitive
638- . orWhereRaw (
639- 'jsonb_path_exists(instruments, \'$[*]. name \\? (@.type() == "string" && @ like_regex :searchText: flag "i")\') ' ,
640- { searchText : filter . text }
630+ . orWhereJsonFieldLikeEscaped (
631+ 'instruments' ,
632+ 'name' ,
633+ ` ${ filter . text } `
641634 )
642635 ) ;
643636 }
0 commit comments