Monday, October 30, 2023

How to create CompositeQueryFilter for Sitecore Content Hub Web Client SDK?

Sitecore content hub allows us to define our own query and get it executed using the query client. In order to combine one or more query filters, we have to use CompositeQueryFilter which comes with Sitecore Content Hub OOTB.

This blog will tell you the significance of CompositeQueryFilter and guide you to create CompositeQueryFilter using the Web Client SDK.

The query object has a set of parameters that are required to be populated, and the details are mentioned in the following link.

https://docs.stylelabs.com/contenthub/4.1.x/content/integrations/sdk-common-documentation/query/query-filters.html

The following code snippet covers:

How to create a Property Filter?

How to create a Relation Filter?

How to combine two filters in a list?

How to create a Composite Query Filter?

How to send query requests?

Sample code for CompositeQueryFilter:

PropertyQueryFilter anyNameQueryFilter = new PropertyQueryFilter
{
 Property = "AnyName",
 DataType = FilterDataType.String,
 Operator = ComparisonOperator.Contains,
 Value = "SPJ"
};
 
RelationQueryFilter anyRelationFilter = new RelationQueryFilter
{
 Relation = "C.Categoty",
 ParentId = 5678
};
 
List<QueryFilter> filtersList = new List<QueryFilter>();
queryFiltersList.Add(anyNameQueryFilter);
queryFiltersList.Add(anyRelationFilter);
 
CompositeQueryFilter compositeQueryFilter = new CompositeQueryFilter
{
 Children = filtersList
};
var newQuery = new Query
{
 Take = 10,
 Filter = compositeQueryFilter
};
 
var res = await MConnector.Client().Querying.QueryAsync(newQuery);
                                                    Happy learning!

How to Create a Public Link Using the Sitecore Content Hub REST API

Creating a public link using the Sitecore Content Hub REST API is a straightforward process that enables you to share content externally whi...