Share via


How to Create a Search Clause

For the latest version of Commerce Server 2007 Help, see the Microsoft Web site.

You create a search clause to specify the conditions that a basket or purchase order must meet in order to be included in the results of a search.

To create a search clause

  1. Create an OrderManagementContext object.

    For information about creating an OrderManagementContext object, see How to Create an OrderManagementContext Object.

  2. If you are searching baskets, get the BasketManager object from the OrderManagementContext object. If you are searching purchase orders, get the PurchaseOrderManager object from the OrderManagementContext object.

  3. Call the GetSearchableProperties method for the type of object you want to search. For baskets, call the GetSearchableProperties method of the BasketManager object. For purchase orders, call the GetSearchableProperties method of the PurchaseOrderManager object.

  4. Call the GetSearchClauseFactory method for the type of object you want to search. For baskets, call the GetSearchClauseFactory method of the BasketManager object. For purchase orders, call the GetSearchClauseFactory method of the PurchaseOrderManager object.

  5. Create a SearchClause object by calling the CreateClause method of the OrderSearchClauseFactory object.

    Note

    To determine which properties of the basket or purchase order you can search, examine the DataSet object that the GetSearchableProperties method returns. Your search clause can refer to any property in any table of this DataSet.

  6. To create an AND clause, create another SearchClause object, and then call the IntersectClauses method of the OrderSearchClauseFactory object to create a SearchClause object that represents the intersection (logical AND) of the two clauses. To create an OR clause, call the UnionClauses method of the OrderSearchClauseFactory object to create a SearchClause object that represents the union (logical OR) of the two clauses.

    The following example code illustrates how to create a search clause to find all baskets that were last modified on or before January 1, 2006 and that contain more than one line item.

    Note

    For complete code examples that illustrate how to create a search clause, see Sample Basket Search Implementation and Sample Purchase Order Search Implementation.

    BasketManager manager = context.BasketManager;
    DataSet searchableProperties = 
        manager.GetSearchableProperties(
        CultureInfo.CurrentUICulture.ToString());
    SearchClauseFactory searchClauseFactory = 
        manager.GetSearchClauseFactory(searchableProperties, "Basket");
    SearchClause lastModifiedClause = 
        searchClauseFactory.CreateClause(
        ExplicitComparisonOperator.OnOrBefore, "LastModified", 
        new DateTime(2006, 1, 1));
    SearchClause lineItemClause = 
        searchClauseFactory.CreateClause(
        ExplicitComparisonOperator.GreaterThan, "LineItemCount", 1);
    SearchClause combinedClause = 
        searchClauseFactory.IntersectClauses(lastModifiedClause,
            lineItemClause);
    

See Also

Reference

SearchClause

Other Resources

Sample Basket Search Implementation

Sample Purchase Order Search Implementation

Searching the Orders Database