How to modify the Request URL in Drupal 8.9 search when selecting a Facet?

I’m working on a Drupal 8.9 site and I’m using the Facet module to add facets to my search. I need to modify the request URL dynamically when a user selects a facet, specifically to add or alter query parameters in the URL based on the selected facets.

To achieve my goal, I’ve created a custom UrlProcessor.

The most important aspect is that when the URL changes and the search results page is reloaded, it should retain the same results as before the modification. I’ve tried different methods, but with all of them, when navigating to the new URL, there are no search results because the modification occurs after the indexing.

Has anyone done this before or could point me in the right direction? Any help or code examples would be greatly appreciated!

Thanks in advance!

What I’ve Tried:

Creating patches for the URL processor of the Facet module.
Modifying the URL in the RouteSubscriber of the module.
Using the PathProcessor in a custom module through the InboundPathProcessorInterface.
With all these methods, I’ve managed to modify the URL, but the new URL doesn’t return results because the modification happens after the indexing.

What I Hope to Achieve:

I want to modify the Request URL using my custom UrlProcessor while retaining the search results that would be obtained without the modifications.