Creating hierarchy searches

You can create hierarchy searches so that users can search for categories in a hierarchy.

Before you begin

Before you can create a hierarchy search, the hierarchy must exist.

About this task

To enable a user to see all the categories in the hierarchy, they must be assigned a special combination of privileges. For example, in order to view all the defined categories, if a role should have access to only hierarchies but not to catalogs, it must have the "view item" access privilege for catalogs.

Procedure

  1. Create the search. Use any one of the following methods: user interface, Java™ API, or script API.
    Option Description
    User interface - rich search simplified
    1. Click Product Manager > Hierarchies > Hierarchy Console.
    2. Choose a hierarchy.
    3. Click Rich Search.
    4. Provide the necessary search details.
    5. Click Search.
    Java API The following sample Java API code creates a hierarchy search, executes it and displays the results.
    Context ctx = PIMContextFactory.getCurrentContext();
    		SearchQuery query = ctx.createSearchQuery(" select category.pk from hierarchy('my hierarchy') where category['myspec/myattribute'] = 'abc' ");
    		SearchResultSet rs = query.execute();
    		while (rs.next())
    		{
    			System.out.println("Primary Key: " + rs.getString(1));
    		}
    
    Script API The following sample script creates a hierarchy search, executes it and displays the results.
    var query = new SearchQuery(" select category.pk from hierarchy('my hierarchy') where category['myspec/myattribute'] = 'abc' ");
    		var rs = query.execute();
    		while (rs.next())
    		{
    			out.writeln("Primary Key: " + rs.getString(1));
    		}
    Query language The following code searches all the categories in a hierarchy. The categories are searched by their primary keys that are mapped.
    select category.pk
    from hierarchy('grocery store item hierarchy')
    where
    category.spec.attribute_path = 'color'
    The search is created, and users can now view it in the left pane.
  2. Optional: Run the search in the Rich search screen.