Make products of vendors that are in the same country that customers appear first in searches

Hello, I am using the multi-vendor edition and expect to have vendors of more than one country in the future.

I would find useful to let the users find those products that are being sold in the same zone or country he lives more easily than those that are being sold far, and will probably have a higher price, considering the shipping charges.

I have tried to modify the code to make products of the same country appear first, for registered users who have specified a country, but I am not succeeding.

I would like to know if there's a way to do it without having to programme much, or how do you think this could be done.