Create a new search expression

Search expressions performed by WebSphere Commerce services use an expression language known as XML Path Language, or, more commonly, XPath. If you are new to XPath, familiarize yourself with the notation before proceeding with this customization task. WebSphere Commerce has also extended the notation for XPath to allow control over the display and ordering of the results, as well as selection of business logic command implementations.

To create a new search expression:

  1. Create a new XPath search expression that describes the search you want to perform. For example, if you want to create a service where the customer can search the catalog based on a price range, use the following XPath to perform the query
    {ibmwcf.ap=$accessProfile$}/CatalogEntry[Price[StandardPrice[Price[(Price[@currency='$currency$']
    and Price >= '$minPrice$')
    and (Price[@currency='$currency$'] and Price <= '$maxPrice$')
    ]]]]
    

    the XPath expression matches the structure of the logical schema. When searching on custom components, a well-defined logical model makes it simpler to write your XPath expressions.

  2. In your customization project,
    create a new service command that implements the FetchNounCmd interface. This command performs the search expression. An example of a new service command can be downloaded; see
    FetchCatalogEntryByPriceRangeTaskCmdImpl.java. See the
    Design pattern for Get service implementation for more information.

    For member subsystem customization, one default fetch command does all the interpretation of the XPath for each noun. You must extend this command to create new search expressions. You need to call super.performExecute() in your performExecute(), and then select your data based on your new XPath query. For example :

       public void performExecute() throws Exception {
                    // Member subsystem code example follows
    (additional code may precede this ...) 
    
                    SelectionCriteriaMapper selectionCriteria = new
    SelectionCriteriaMapper(getGet().getExpression());              
                    Map mapQueryParameters =
    selectionCriteria.getQueryParameters();
    
                    boolean bPersonFound = false;
    
                    // Check if search expression is our customized
    expression based on LogonID: 
    /Person[Credential[(LogonID='$logonID$')]]
                    
                    if (mapQueryParameters.get("LogonID") != null) {
    
                            // Add customized code to find Person by
    logon ID ...
    
                            bPersonFound = true;
    
                    }
    
                    // if Person was not found, call parent class for
    default expressions
                    if (!bPersonFound) {
                            super.performExecute():
                    }
    
                    //Code example ends -- additional code may follow
    this 
            }
    

  3. Register your new command. When you do so, associate the XPath search expression key with your new custom fetch command implementation with an SQL statement. For example
    insert into cmdreg (STOREENT_ID, INTERFACENAME, CLASSNAME,TARGET)
    VALUES 
    (0,'com.ibm.commerce.catalog.facade.server.commands.FetchCatalogEntryCmd+/CatalogEntry[Price[StandardPrice[Price[(Price<=
    and Price[@currency=]) 
    and (Price>= and Price[@currency=])]]]]',
    'com.mycompany.commerce.customization.catalog.FetchCatalogEntryByPriceRangeTaskCmdImpl',
    'Local');
    

    that the interface name contains the name of the command concatenated with the XPath.

    For member subsystem customization, you need to update the CMDREG entry for the existing default fetch command. Also, no XPath details are included in the SQL update.

  4. Restart WebSphere Commerce

Related concepts

WebSphere Commerce services
WebSphere Commerce service module
Component facade interfaces
Design patterns
Design pattern for Get service implementation

Related tasks

Create the component facade
Extending a noun
Create the service command


Related Reference


WebSphere Commerce extended XPath notation