Exclude clause

The search filter can be built to exclude certain items by using an exclude tag clause.

The following code sample shows how to get a list of products in the product catalog module through search. It has the following search filtering:

  • Search all products
  • which are published
  • which has a particular product group id
  • excluding all products which has the value "Hardcover" for the property field named SamplePrintFormat.
        /// <summary>
        /// Gets the published products except all products which has hardcover as the value in SamplePrintFormat property field.
        /// </summary>
        /// <param name="languageId">The language id.</param>
        /// <param name="productGroupId">The product group id.</param>
        /// <returns></returns>
        private System.Collections.Generic.List<Product> GetPublishedProductsExcept(Guid languageId, Guid productGroupId)
            //find all products which has a common parent of "productGroupId" above.
            var request = new QueryRequest(languageId, ProductCatalogSearchDomains.Products, FoundationContext.Token);
            //only published products.
            request.FilterTags.Add(new Tag(TagNames.IsPublished, true));
            //parent should be this product group.
            request.FilterTags.Add(new Tag(TagNames.ProductGroupTreeId, productGroupId));

            //exclude all Hardcover books.
                //printformat tag name for "SamplePrintFormat" property
                var printFormat = TagNames.GetTagNameForProperty("SamplePrintFormat");
                request.ExcludeTags.Add(new Tag(printFormat, "Hardcover"));

            var response = Solution.Instance.SearchService.Search(request);
            var productList = Product.GetProducts(response.Hits.Select(x => new Guid(x.Id)));
            return productList;
Is this page helpful?
Thank you for your feedback!