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) andMibServerApi@releases/7.0(the consumer); the engine code is identical onreleases/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 itsTEXTcolumn, with placeholders{VALUES},{<MEDIA_TYPE>},{CONTEXT_IDS}(e.g.ID IN ({VALUES})). There is no operator field — the comparison (=,IN,LIKE, a correlatedCOUNT(*)…>0subquery, anything) is baked into the SQL.SEPARATORsplits the stored value string;VALUE_TYPE_ID(Integer/String/NoValue) types the bound parameters. An order is an availableORDER BYfragment ("NAME DESC"). - Selection (
CONTENT_SELECTION+_FILTERS+_ORDER+_HIGHLIGHTS) — what an editor actually chose: a filter tree, a topOperator, chosen orders (by integer rank), pinnedHighlights, andMaxResults(0= unlimited).
How the query is built
- Filter tree (two-level boolean).
ContentSelectionFilterTreeHelper.GenerateBasicTree(Model/Helper/ContentSelectionFilterTreeHelper.cs:9) buckets filters by group: within a group, filters join by that group'sGroupOperator(default AND); groups join by the selection's topOperator(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). - SQL mounting.
ContentCriteriaLoader.GetQuerycompilesSELECT ID FROM <MediaType> (NOLOCK) WHERE <tree>as a raw string with positional?parameters.{VALUES}→?,?,…(values split bySEPARATOR, typed perVALUE_TYPE_ID);{<MEDIA_TYPE>}→ that type's numeric MIBINDEX. OR nodes consolidate same-TEXTfilters into oneIN (?,?,…)with de-duplicated values; AND nodes emit one clause each; every node is parenthesized so precedence can't leak. - 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. - Ordering. Chosen orders are applied sorted by rank (1 = primary, 2 = secondary…); direction is
literal
ASC/DESCinside the fragment; duplicate columns are stripped. - 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.
- Caching. Every query is memoized in
MibCachekeyed onhash(mediaType, text, params, offset, limit), TTL fromMibObjectCacheConfigsectioncontentCriteria— 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'sContentCriteriaComponent→ListWorkflow.GetList→ItemRepository.GetListconverge 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; theCONTENT_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— itscontentCriteriasection sets the per-media-type result-cache TTL (allfallback).
Authoring a blueprint (add a filter / an order)
- Expose a filterable field: seed one
CONTENT_CRITERIA_FILTERSrow whoseTEXTis a SQL predicate over the media type containing{VALUES}(plus optional{<MEDIA_TYPE>}index tokens declared inREQUIRED_MEDIA_TYPES), aSEPARATOR, and aVALUE_TYPE_ID. Package helper:ContentCriteriaHelper.AddContentCriteria/AddContentCriteriaFilter(filterText: "ID IN ({VALUES})", filterSeparator: ","). - Expose a sort: seed a
CONTENT_CRITERIA_ORDERrow whoseTEXTis anORDER BYfragment. - 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 viaurlMicroService). 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
timeoutmax time in seconds to wait for HTTP request completion (default 100)maxRetriesmax times the request should be reattempted in case of failure (default 3)retryIntervalinterval in seconds between request retries (default 2)
Example:
MIBCONTENTCRITERIAMICROSERVICECLIENTCONFIG_DEFAULT_URLMICROSERVICE=mibcontentcriteriaservice
MIBCONTENTCRITERIAMICROSERVICECLIENTCONFIG_DEFAULT_TIMEOUT=100
MIBCONTENTCRITERIAMICROSERVICECLIENTCONFIG_DEFAULT_RETRYINTERVAL=5
MIBCONTENTCRITERIAMICROSERVICECLIENTCONFIG_DEFAULT_MAXRETRIES=5