Adding custom search filter throws Unhandled Rejection (TypeError): Cannot read properties of undefined (reading 'totalResults')

I think the problem is that you're not explicitly returning your values. You should explicitly add the return statement:

     beforeSearchCall: (options, next) => {
       console.log('queryoptions', options);
       if(!countrySelected&&!languageSelected)
       return next({
         ...options,
         filters: [
          {
            field: 'regioncountrylist',
            values: [countrySelected],
            type: 'any',
          },
          {
            field: 'language',
            values: [languageSelected],
            type: 'any'
          }
        ]
       })

Have a look at other options for achieving this in this post.