How to fix pagination counting hidden items in search results?

Okay, so I’m trying to take a crack at the issue of the search results pagination still counting hidden items, and I think I’m…most of the way there.

So I’ve created a duplicate set of products, one tagged with “Wholesale” and one tagged with “Retail”

Thanks to this article I’ve successfully excluded Retail products from searches by wholesale customers and vice versa. However, the search.results_count still shows the “doubled number” (meaning it’s counting both wholesale and retail products, even though only half are being rendered), and that’s also messing up the pagination of the results.

After spending a LONG time trying to find a solution to this, I realized that you can use boolean search terms in the search bar, so if I search " ‘product’ AND tag:Wholesale" I get the correct results count and correct pagination.

So (hopefully) the last step is this: is there a way to do something like this?

{% if customer.tags contains ‘Wholesale’ %}

I’ve tried it, and there are two issues that come up: first, it does successfully append that to the search terms, but it doesn’t actually search for both terms.

I get this:


but all I do is hit search again and it runs correctly, returning this:

So I have no idea why that’s happening, but the second issue is visible in both of those pictures: the customer can just see the added search term. So if there were a way to append the second search term, have it run successfully the first time, and remain hidden from the customer, that’d be ideal.

Any ideas?