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
Which products should be indexed are defined by flexible search queries.
You find them in hmc/backoffice
by navigating to System/Facet Search/Indexed Types
. Select your indexed type. There you find full and update queries.
The full query is used by a Full SolR Indexer CronJob
which runs in the default case every night and recreates the SolR index completely. The update query similarly is used by a Update SolR Indexer CronJob
which runs by default every hour and just updates products which have been changed in between. Therefore you find something like WHERE {sl:modifiedtime} >= ?lastIndexTime
in the update query, which is missing in the full query.
You can change the query in every way you need it. E.g. assuming your query is:
SELECT {pk} FROM {Product}
change it to
SELECT {pk} FROM {Product} WHERE {myAttribute} LIKE 'index this product'
PS: Find the Solr Indexer Cronjobs
on your associated Facet Search Config (System/Facet Search/Facet Search Config
).
PPS: There is also a delete query, where you define products which should be removed from SolR
index.
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.
<bean parent="modifyPopulatorList">
<property name="list" ref="commerceSearchQueryPageableConverter" />
<property name="add" ref="mySearchFiltersPopulator" />
</bean>