@@ -151,6 +151,7 @@ export class RecordQueryBuilderService implements IRecordQueryBuilder {
151151 sort : options . sort ,
152152 currentUserId : options . currentUserId ,
153153 defaultOrderField : options . defaultOrderField ,
154+ hasSearch : options . hasSearch ,
154155 } ) ;
155156 this . buildFieldCtes ( qb , tables , state , options . projection ) ;
156157 }
@@ -184,6 +185,7 @@ export class RecordQueryBuilderService implements IRecordQueryBuilder {
184185 sort,
185186 currentUserId,
186187 defaultOrderField : options . defaultOrderField ,
188+ hasSearch : options . hasSearch ,
187189 } ) ;
188190
189191 this . buildSelect (
@@ -297,9 +299,10 @@ export class RecordQueryBuilderService implements IRecordQueryBuilder {
297299 sort ?: ISortItem [ ] ;
298300 currentUserId ?: string ;
299301 defaultOrderField ?: string ;
302+ hasSearch ?: boolean ;
300303 }
301304 ) : void {
302- const { limit, offset, filter, sort, currentUserId, defaultOrderField } = params ;
305+ const { limit, offset, filter, sort, currentUserId, defaultOrderField, hasSearch } = params ;
303306 state . setBaseCteName ( undefined ) ;
304307
305308 if ( state . getContext ( ) !== 'table' ) {
@@ -316,6 +319,11 @@ export class RecordQueryBuilderService implements IRecordQueryBuilder {
316319 return ;
317320 }
318321
322+ if ( hasSearch ) {
323+ // Avoid trimming candidate rows before search filter applies; search runs after base CTE.
324+ return ;
325+ }
326+
319327 const requiredFieldIds = this . collectRequiredFieldIds ( filter , sort , defaultOrderField ) ;
320328 const fieldLookup = this . buildFieldLookup ( table ) ;
321329
0 commit comments