Suppose I have a requirement whereby I don\'t want to search the products on the Hybris
frontend having a specific attribute value. Even if the following products a
I can think of two ways to achieve product visibility on front-end using Solr.
1. Index only those products what you need. As said by @Johannes Nolte, Adjust Full and Update Index Query
The problem here is this way completely remove products from search. If there is a requirement where you need to show/hide products based on some other attribute, you can't do it.
Other way is
2. Add Search Filter before hitting actual Solr Query to Solr Server
Suppose you want to show/hide product based on productType (Type A & Type B)
User 1 is eligible to see Type A product, User 2 is eligible to see Type B product.
You need to first index your productType attribute and make it facet=true. Make sure you select visible=false so that this attribute should not be visible in facet on storefront.
See OOTB SearchFiltersPopulator class, you will get an idea how we can add dynamic filter in Solr query before sending to Solr Server for search.
Similarly You can create your own filterPopulator e.g. MySearchFiltersPopulator which contains your custom visibility logic.
if Current_User is User 1
target.getSearchQuery().addFacetValue("productType", "Type A");
else Current_User is User 2
target.getSearchQuery().addFacetValue("productType", "Type B");
Finally add custom populator in commerceSearchQueryPageableConverter
chain.