Optimising search query
It's hard to see what you're actually trying to achieve here, but yes it's likely to do with the amount of queries you're doing on the page.
I would either re-consider the page layout (without knowing what you're trying to achieve by having two loops it's hard to judge) OR pull some, or all of the results asynchronously using javascript so the page rendering isn't blocked whilst the query is being processed.
The newly released sprig plugin may be of interest.