Content - Filtering

Content Filtering

Content can be filtered by tag, type, or id. The Content Manager Window can filter the viewable content. Content can be filtered from the SDK as well.

Filter Strings

Content filter strings can be entered into the Content Manager's search box, or into the GetManifest function in the SDK. Filter strings follow the same conventions that Unity search strings do. The type of the filter is specified first, followed by a : character, and the query for the filter is specified last.

Type Filtering

To filter by content type, use the t filter constraint. The following table shows examples of type constraints.

Filter StringDescription
t:currencyreturns all content elements that are of type "currency"
t:currency itemsreturns all content elements that are of type "currency" or "items"

Tag Filtering

To filter by content tag, use the tag filter constraint. The following table shows examples of tag constraints.

Filter StringDescription
tag:areturns all content elements that have the "a" tag
tag:a breturns all content elements that have the "a" tag and the "b" tag

Id Filtering

To filter by content id, use the id filter constraint, or use no constraint at all. The id filter constraint is the default constraint. The following table shows examples of id constraints.

Filter StringDescription
gemsreturns all content elements that contain "gems" in their name
id:gemsreturns all content elements that contain "gems" in their name

Compound Filtering

Multiple filter constraints may be combined if separated by a , character. The following table shows examples of compound constraints.

Filter StringDescription
t:currency, gemsreturns all content elements that are of type "currency", and contain "gems" in their name
t:currency, tag:basereturns all content elements that are of type "currency", and have the "base" tag
gems, tag:areturns all content elements that contain "gems" in their name, and have the "a" tag

Structured Filtering

In the SDK, the GetManifest function accepts a filter string, as shown in the example below.

public async Promise<IList<IContentObject>> LoadMyTaggedContent(string tag)
{
    var ctx = BeamContext.Default;

    // load a manifest that only has content including the request tag
    var manifest = await ctx.Content.GetManifest($"tag:{tag}");

    // resolve all the content in that manifest
    var content =  await manifest.ResolveAll();

    return content;
}	

Filter strings do not grant type safety in the SDK, and are more prone to bugs and unintentional filtering. The above sample can be re-written with the ContentQuery class instead of the filter string. The ContentQuery allows the developer to specify constraints in a type safe way and will avoid filter serialization bugs.

public async Promise<IList<IContentObject>> LoadMyTaggedContent(string tag)
{
   var ctx = BeamContext.Default;
   var manifest = await ctx.Content.GetManifest(new ContentQuery
   {
     TagConstraints = new HashSet<string>{ tag }
   });
   var content =  await manifest.ResolveAll();
   return content;
}