Create a SearchAfterQuery query
You can search for specific entities in Sitecore Content Hub using a SearchAfterQuery query. The SearchAfterQuery does not itself query entities; it describes the querying conditions. It is the querying client that is responsible for running queries and it requires a defined SearchAfterQuery query. The SearchAfterQuery object supports the following parameters:
-
Filter- the type of filter to be invoked. -
Take- the number of entities to be retrieved. -
Sorting- the sorting options to be applied. -
LoadConfiguration- the load configuration to be applied. -
SearchAfter- a list of sort values to retrieve the next page of results. -
Renditions- the renditions to be applied. -
NestedRelations- the nested relations to be applied.
Query filters
You use the QueryFilterBuilder to create filters, as shown in the following examples.
Query by definition name
The following example queries by definition name.
const filter = new DefinitionNameQueryNodeFilter({ name: "M.Asset" });Query by definition ID
The following example queries by definition ID.
const filter =new DefinitionIdQueryNodeFilter({ id: 40 });Query by created by user
The following example queries by user.
const filter = new CreatedByQueryNodeFilter({ userId: 6 });Query by full text
The following example queries by full text property.
const filter = new FullTextQueryNodeFilter({ value: "text" });Query M.Asset entities
The following example queries for M.Asset entities with a title equal to my asset.
const query = new SearchAfterQuery({
filter: new LogicalQueryNodeFilter({
operator: LogicalOperator.And,
left: new StringPropertyQueryNodeFilter({
propertyName: "Title",
operator: QueryNodeFilterOperator.Equals,
value: "my asset",
}),
right: new DefinitionNameQueryNodeFilter({ name: "M.Asset" }),
}),
sorting: [
new Sorting({ field: "created_on", fieldType: SortFieldType.Property, order: QuerySortOrder.Desc }),
],
take: 1,
});
var results = await client.querying.searchAfterAsync(query);
// query for the next set of results
query.searchAfter = actual.lastHitData;
results = await client.querying.searchAfterAsync(query);