How can I create an AssetSearchFilter to find assets without a Collection assigned?
Stretch goal, how can I get an asset count of the filtered results?
await project.CountAssetsAsync(CancellationToken.None);
is a little too coarse.
How can I create an AssetSearchFilter to find assets without a Collection assigned?
Stretch goal, how can I get an asset count of the filtered results?
await project.CountAssetsAsync(CancellationToken.None);
is a little too coarse.
Hey Tony,
Sorry for the delayed answer!
You can use ‘/’ as a search string for the collection:
AssetSearchFilter assetSearchFilter = new AssetSearchFilter();
assetSearchFilter.Collections.WhereContains("/");
You can use a query builder like so:
GroupAndCountAssetsQueryBuilder queryBuilder = project.GroupAndCountAssets()
.SelectWhereMatchesFilter(assetSearchFilter)
.LimitTo(int.MaxValue); // By default, max 100 count per value is returned
// Select a filter to group by, here we're choosing to group assets by type.
IReadOnlyDictionary<string, int> results = await queryBuilder.ExecuteAsync(GroupableField.Type, CancellationToken.None);
foreach (var kvp in results)
{
// Each kvp represents an asset type (key) and the count of assets for that type (value).
}
Hope this helps!
Thanks Chafik!