How can I achieve to show related products if the searched product is not available?

I am trying to achieve certain behaviour. Let me explain by example.

I have products available in various sizes.

Size is set on searchable attributes for sure along with name and other attributes.

Let’s say I have 5 sizes, 30cm , 40cm, 50c, 60cm, 70cm.

Now if user searches for “product name 30cm”. I want to show only “product name 30cm”.

If the user searches for “product name 40cm”. I want to show only “product name 40cm”.

However…

If the user searches for “product name 95cm” which is not available, I want to show all the available variants instead of giving a blank page on search.

How can I achieve this behaviour? Which settings will I have to customize? My guess is word proximity, but not really sure along with that what else should go in order to achieve this behaviour.