Search Restriction is a crucial concept in SAP Commerce Cloud(Hybris). It is used in most of the projects.
What is Search Restriction? Search Restriction is a set of rules which is applied on Flexible Search Query in order to limit the search results or to filter search results based on specific condition.
It is a transparent process and in most of the cases business logic layer remains unchanged. It is applied on the item type level and by default restrictions do not apply on admin users. We can create restrictions for users who use HAC to fetch the data or for the Storefront users.
We create restrictions via impex. All the search restrictions are store in SearchRestriction item type and extension is core.
How Search Restriction work? When ever a flexible search query fires it appends where clause at the end of the query with the specified condition mentioned.
Where can we use Search Restriction? There are couple of scenarios where it can be useful for ex:
- To show only those orders which were placed in last 6 months on order history page.
- To show some special category only for the registered users.
- To show some special discounted products to the logged in users.
- To allow customers to provide review if they are not blocked.
- Integration Objects to be visible only to admin group
There could be n number of scenarios where we can use Search Restriction.
How To create Search Restriction? There are two ways to create a search restriction
- From Backoffice
- Via Impex
To create from Backoffice Go to Backoffice > Types > SearchRestriction click on + icon
- Restricted type: Item type to which restriction has to be applied (for ex Customer : select * from {Customer})
- Identifier: Code of Search Restriction
- Time created: Created time
- Owner can be left blank
- Filter: Restriction to be applied ({uid}!='testacocunt@gmail.com') now whenever any one will fire query to Customer table this restriction will be applied and will not show this user in results.
- Apply on: Upon which group this restrction should be applicable( for ex: user is of employeegroup) now when ever an user from employeegroup will fire any flexible query on Customer table he/she will not be able to see this 'testacocunt@gmail.com' customer in results.
- Active: true to enable restriction | false to disable restriction
To create via impex
INSERT_UPDATE SearchRestriction;code[unique=true];principal(uid)[unique=true];query;restrictedType(code)[unique=true];active;generate
;backendOrderVisibility;customersupportagentgroup;{versionID} IS NULL;Order;true;true
- (Identifier)Code: backendOrderVisibility
- (Apply on) principal(uid)[unique=true]: customersupportagentgroup
- (Filter) query: {versionID} IS NULL
- (Restricted type) restrictedType: Order
- active: true
- generate: true
Not so tough but a crucial role in SAP Commerce Cloud. Mostly you will see search restriction in every project.