This question has 2 dimensions: one of them totally off topic (the implementation side) and the other being the UX side. Luckily, even the implementation side has been covered by Wojciech's answer.
As for the UX part: technically, it can be done. But the question is: why would you want to do this?
See, the idea of searching is to display results based on user's input, including
string, but whenever possible, including sorting and filtering as well, as in your case. If everything goes as expected, the user will be able to access certain information s/he was looking for.
So, you're asking to sort something that hasn't been completed, providing the user with a partial information output that might or might not be what the user was searching for.
Even worse: let's say the user went through some results and lazy loads, and clicks one result. After that, s/he wants to get back to the original results' list because there was something that could be more accurate. Surprise! Now the result is gone and the user has to repeat the loading again until s/he hopefully finds the desired result (or not!)
Please make no mistake, I have seen sites doing this, specially on e-commerce, but it doesn't mean it's correct. You're basically telling the user s/he doesn't have any locus of control and that you don't care at all. Furthermore, you're doing things on purpose so this locus of control is lost.
You can do it, and it's technically possible. But I strongly suggest you deal with proper navigation where users can go back and forth as needed with minimal friction