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.
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
);