Table of Contents

Content Criteria

Content Criteria is the engine behind automatic / rule-driven lists — it turns the filter + order composition an editor builds in the Content Criteria Component into a resolved set of content ids. Despite the historical "MicroService" name, in releases/7.0 it is not a REST service: it ships as in-process NuGet libraries that MibServerApi runs directly.

Grounded against MibContentCriteria@releases/7.0 (the engine) and MibServerApi@releases/7.0 (the consumer); the engine code is identical on releases/6.0 — only the library's package references differ.

Architecture — an in-process engine, not a service

The engine is three NuGet libraries, consumed in-process:

Library Role
MediaiBox.ContentCriteria ContentCriteriaLoader — the SQL generator + executor
MediaiBox.ContentCriteria.Model POCOs, interfaces, the filter-tree helper
MediaiBox.ContentCriteria.Database MibObject records over the CONTENT_* tables

MediaiBox.Cms.Api.Model references MediaiBox.ContentCriteria, so resolution runs inside the Data API (MibServerApi) process. The endpoint POST /api/v1/contentselection/process (ApiV1Controller.ListContentSelection, ApiV1Controller.cs:62) calls new ContentCriteriaLoader().GetInt32List(...) against MibApi's own DB connection (MibObjectWorkflow.List.cs:203). There is no HTTP hop to a Content Criteria service — the API is the engine host. (The mib-cms-microservices-contentcriteria image + urlMicroService client config in Legacy configuration describe an older standalone deployment; treat them as historical.)

What gets resolved — blueprint vs selection

  • Blueprint (CONTENT_CRITERIA + CONTENT_CRITERIA_FILTERS + CONTENT_CRITERIA_ORDER) — what a media type can be filtered / ordered by. A filter is a raw-SQL predicate TEMPLATE in its TEXT column, with placeholders {VALUES}, {<MEDIA_TYPE>}, {CONTEXT_IDS} (e.g. ID IN ({VALUES})). There is no operator field — the comparison (=, IN, LIKE, a correlated COUNT(*)…>0 subquery, anything) is baked into the SQL. SEPARATOR splits the stored value string; VALUE_TYPE_ID (Integer / String / NoValue) types the bound parameters. An order is an available ORDER BY fragment ("NAME DESC").
  • Selection (CONTENT_SELECTION + _FILTERS + _ORDER + _HIGHLIGHTS) — what an editor actually chose: a filter tree, a top Operator, chosen orders (by integer rank), pinned Highlights, and MaxResults (0 = unlimited).

How the query is built

  1. Filter tree (two-level boolean). ContentSelectionFilterTreeHelper.GenerateBasicTree (Model/Helper/ContentSelectionFilterTreeHelper.cs:9) buckets filters by group: within a group, filters join by that group's GroupOperator (default AND); groups join by the selection's top Operator (default OR). ⚠️ Asymmetric defaults — unset top → OR, unset group → AND. The tree is at most two levels; e.g. A,B in group 1 + C in group 2 → (A AND B) OR (C).
  2. SQL mounting. ContentCriteriaLoader.GetQuery compiles SELECT ID FROM <MediaType> (NOLOCK) WHERE <tree> as a raw string with positional ? parameters. {VALUES} → ?,?,… (values split by SEPARATOR, typed per VALUE_TYPE_ID); {<MEDIA_TYPE>} → that type's numeric MIBINDEX. OR nodes consolidate same-TEXT filters into one IN (?,?,…) with de-duplicated values; AND nodes emit one clause each; every node is parenthesized so precedence can't leak.
  3. Restrictions. Caller-supplied raw-SQL predicates are ANDed around everything — this is how the ?filter= querystring and the user's source-permission SQL compose with the criteria.
  4. Ordering. Chosen orders are applied sorted by rank (1 = primary, 2 = secondary…); direction is literal ASC/DESC inside the fragment; duplicate columns are stripped.
  5. Highlights. Pinned ids are prepended to the results and excluded from the main query (so a pin never appears twice); they bypass the filter tree but are still validated against restrictions.
  6. Caching. Every query is memoized in MibCache keyed on hash(mediaType, text, params, offset, limit), TTL from MibObjectCacheConfig section contentCriteria — list results can lag a save until the TTL expires.

Injection posture: values are always parameterized (?); the table name, filter TEXT, and restriction/order text are interpolated raw and are trusted-admin content. Editors send only filter ids — the SQL templates are read from the persisted blueprint, never from the request.

The resolve path (consumer side)

POST /api/v1/contentselection/process takes a ContentSelectionRequestInformation: _criteriaMediaType, _contentCriteriaId, _filters[] (each just _criteriaFilterId + _groupNumber

  • _groupOperator + _value), _globalFilters[], _selectionOrders[], _contentRestrictions[], _highlights[], _operator, _maxResults, _page/_limit, _contextIds[]. The BFF's ContentCriteriaComponent → ListWorkflow.GetList → ItemRepository.GetList converge on this endpoint for both live preview and saved-list render.

Configuration (in-process)

  • MibDatabaseConfig (required) — the content DB (the same datamodel/core DB MibServerApi uses; the CONTENT_CRITERIA* / CONTENT_SELECTION* tables live there as ordinary media types). Because the engine runs inside MibServerApi, this is just MibApi's existing content-DB configuration — there is no separate service database.
  • MibObjectCacheConfig — its contentCriteria section sets the per-media-type result-cache TTL (all fallback).

Authoring a blueprint (add a filter / an order)

  • Expose a filterable field: seed one CONTENT_CRITERIA_FILTERS row whose TEXT is a SQL predicate over the media type containing {VALUES} (plus optional {<MEDIA_TYPE>} index tokens declared in REQUIRED_MEDIA_TYPES), a SEPARATOR, and a VALUE_TYPE_ID. Package helper: ContentCriteriaHelper.AddContentCriteria / AddContentCriteriaFilter(filterText: "ID IN ({VALUES})", filterSeparator: ",").
  • Expose a sort: seed a CONTENT_CRITERIA_ORDER row whose TEXT is an ORDER BY fragment.
  • Runtime CONTENT_SELECTION* rows are created by editors through the BFF, not seeded by authors.

Legacy standalone-service configuration (historical)

The settings below configured Content Criteria as a standalone container (image mib-cms-microservices-contentcriteria, default port 8637, consumed by MibServerApi over HTTP via urlMicroService). On the in-process path documented above they are not used; kept here for operators still running the older deployment.

Server Side

MibDatabaseConfig - Required

Configuration used to indicate the content database, which is the one also used by MibServerApi.

Example:

MIBDATABASECONFIG_CONTENT_TYPE=sql2005
MIBDATABASECONFIG_CONTENT_SERVER=services.mediaibox.com.br
MIBDATABASECONFIG_CONTENT_DATABASE=content
MIBDATABASECONFIG_CONTENT_USERNAME=username
MIBDATABASECONFIG_CONTENT_PASSWORD=secret

MibContentCriteriaMicroServiceServerConfig

Configurations for the MibMiddleware (enable Swagger, Serilog and other things). Refer to MibMiddlewareConfig for complete list of configuration keys.

Example:

MIBCONTENTCRITERIAMICROSERVICESERVERCONFIG_DEFAULT_ENABLEMETRICS=true
MIBCONTENTCRITERIAMICROSERVICESERVERCONFIG_DEFAULT_ENABLEMIBLOGPROVIDER=true

MibLogConfig

Defines general configurations for logging. Please refer to MibLogConfig for complete list of configuration keys.

MibCacheConfig

Defines general configurations for caching. Please refer to MibCacheConfig for complete list of configuration keys.

MibObjectCacheConfig

Defines cache preferences for Mib Objects.


Client Side (MibServerApi)

MibContentCriteriaMicroServiceClientConfig - Required

Configures behavior for the client of the Content Criteria Service.

Required

  • urlMicroService - url of the MibContentCriteria service

Optional

  • timeout max time in seconds to wait for HTTP request completion (default 100)
  • maxRetries max times the request should be reattempted in case of failure (default 3)
  • retryInterval interval in seconds between request retries (default 2)

Example:

MIBCONTENTCRITERIAMICROSERVICECLIENTCONFIG_DEFAULT_URLMICROSERVICE=mibcontentcriteriaservice
MIBCONTENTCRITERIAMICROSERVICECLIENTCONFIG_DEFAULT_TIMEOUT=100
MIBCONTENTCRITERIAMICROSERVICECLIENTCONFIG_DEFAULT_RETRYINTERVAL=5
MIBCONTENTCRITERIAMICROSERVICECLIENTCONFIG_DEFAULT_MAXRETRIES=5