Predicate Evaluator in Detail

A predicate evaluator handles the evaluation of certain predicates, which are the defining constraints of a query.

It maps a higher-level search constraint (such as "width > 200") to a specific JCR query that fits the actual content model (e.g. metadata/@width > 200). Or it can manually filter nodes and check their constraints.

Note:

For more information about the PredicateEvaluator and the com.day.cq.search package see the Java documentation.

Implementing a Custom Predicate Evaluator for Replication Metadata

As an example this section describes how to create a custom predicate evaluator that helps data based on the replication metadata:

cq:lastReplicated that stores the date of the last replication action

cq:lastReplicatedBy that stores the id of the user who triggered the last replication action

cq:lastReplicationAction that stores the last replication action (e.g. Activation, Deactivation)

Querying Replication Metadata with Default Predicate Evaluators

The following query fetches the list of nodes in /content branch that have been activated by admin since the beginning of the year.

This query is valid but hard to read and does not highlight the relationship between the three replication properties. Implementing a custom predicate evaluator will reduce the complexity and improve the semantic of this query.

Objectives

The goal of the ReplicationPredicateEvaluator is to support the above query using the following syntax.

Writing The ReplicationPredicateEvaluator

The cq-search project contains the AbstractPredicateEvaluator abstract class. This can be extended with a few steps to implement your own custom predicate evaluator(PredicateEvaluator).

Note:

The following procedure explains how to build an Xpath expression to filter data. Another option would be to implement the includes method that selects data on a row basis. See the Java documentation for more information.

Create a new Java class which extends com.day.cq.search.eval.AbstractPredicateEvaluator