Zend certified PHP/Magento developer

Magento 2.4 modify search logic

At the moment I have products that have the visibility of “catalog & search” and of “search”.

When a user performs a search on the site I only want products that have a visibility of “catalog & search” unless the search term starts with a “63”. If the search term starts with a “63” then I want all products with visibility of “catalog & search” and of “search”.

What is the best way of doing this? I have tried by adding in a default layered navigation filter but the pagination doesnt match the number of search results