close

Filter

Adaptive Personalization Manual / Version 2207

Table Of Contents

4.3 Working With Selection Rule Lists

Content Selection Rules allow an editor to define a set of rules that determine which content items to show based on the active user's context. For example, the entry page of a site could take the user's local time into account when selecting a welcome message. To this end, rules that determine what to show under certain conditions are stored in a document property which is evaluated in the CAE at time of delivery.

A selection rule is of the general form:

select <some content> if <some conditions>

Here <some content> specifies the content to be selected if <some conditions> evaluate to true. The content is specified by its unique id using the syntax content:<id>, while conditions are specified using <context property name> <operator> <value>.

<context property name>

The <context property name> can have two different forms:

  • It can consist of the name of the context object, followed by a dot ('.') and followed by the name of the context property you want to test in the condition.

Example:

select content:23 if count.foo > 12
  • It can consist of the name of the context object, followed by some more information in brackets ('[]'). Using this notation, the information can simply consist of the context property name, or of a content ID using the syntax content:<id>, or an arbitrary string in double quotes. The property name is handled as in the form above.

Example:

select content:23 if count[foo] > 12
select content:23 if count[content:12] > 12
select content:23 if count["some complex key"] > 12

<operator>

<operator> is one of the supported comparison operators. These are:

Operator Description
= Equals
< Less than
<= Less than or equal
> Greater than
>= Greater than or equal
!= Not equal
# Contains as substring. Only used for string literals

Table 4.1. Supported operators


<value>

<value> is the literal value to compare the property value to. Supported types are:

Type Description
Boolean true or false
Float Examples: 2.34, 0.543e-12
Integer Examples: 42, 1093
Date A date in ISO8601 format (yyyy-mm-ddThh:mm:ss) 2010-12-15T17:08:52, for instance
Time Time of day in the format hh:mm:ss, 23:01:00, for example
String A string literal enclosed in double quotes. Java escape sequences are supported. Examples: "foo", "frob\\\bnitz"
ContentId A representation of a content ID, following the syntax content:<id>. For example, content:4712. Only equal and not equal operators are supported.

Table 4.2. Supported values


The Evaluation of a condition is performed as follows:

  1. Determine the type of the value used in the condition.

  2. Retrieve the value of the context property.

  3. If the type of the context property value can be compared to the type of the condition value, perform the comparison.

  4. Otherwise, evaluate to false.

If the context does not contain the property specified in the condition, the behavior depends on the type of the comparison value:

Type Behavior
Boolean Assume property is false
Float Assume property is 0
Integer Assume property is 0
Date Evaluate to false
Time Evaluate to false
String Evaluate to false
ContentId Evaluate to false

Table 4.3. Behavior when the context does not contain the specified property


Conditions can be combined using "and" and "or" in their familiar semantics. Furthermore, negation (not) and parentheses are supported. Thus, the following is a valid condition:

behavior.good = true and not
  (datetime.date > 2010-12-25T00:00:00 or vcard.name = "Santa")

Rules are separated via a newline character or a semicolon, for example

select content:23 if count.foo > 12; select content:42 if count.foo < 5
The SelectionRuleProcessor

Rules are evaluated by an instance of SelectionRuleProcessor. Its constructor expects a string containing the rules which are transformed into a representation that can be evaluated very efficiently. The process* method apply the rules to the supplied ContextCollection and return a list of all content items selected in order of their corresponding rules.

The SelectionRuleProcessor can only access context objects of type PropertyProvider, so make sure that all properties you are using in your rules are accessible via such an object. All context classes supplied with CoreMedia Adaptive Personalization implement the PropertyProvider interface.

SelectionRuleProcessor instances can and should be cached, because the process of transforming a string of rules into an internal representation is expensive and not user or context dependent. The recommended pattern is to add a property getter to your content beans that returns a SelectionRuleProcessor instance representing the rules stored in the associated document, then define a data view on the getter with association type static. See the Content Applications Developer Manual for a detailed description of data views.

Caching SelectionRuleProcessor instances

Figure 4.8. Caching SelectionRuleProcessor instances


Saving Rules as an XML Property

Selection Rules created via CoreMedia Studio are saved in XML format using the grammar coremedia-selectionrules-1.0. In this representation, references to content objects (including customer segment definitions) are encoded as xlink attributes allowing the CoreMedia Content Server to check whether the referenced content is available on the live servers before publishing the rules.

To convert rules in XML format into the plain text format expected by the SelectionRuleProcessor, use the helper class XMLCoDec.

Search Results

Table Of Contents
warning

Your Internet Explorer is no longer supported.

Please use Mozilla Firefox, Google Chrome, or Microsoft Edge.