4

I'm trying to implement PredicateEvaluator for ordering purpose only - no filtering.

So I started with:

public class OrderByTagPredicate implements PredicateEvaluator {


private static final Logger log = Logger.getLogger(OrderByTagPredicate.class.getSimpleName());

public OrderByTagPredicate() {
    super();
}

@Override
public Comparator<Row> getOrderByComparator(final Predicate predicate, final EvaluationContext context) {
    return new Comparator<Row>() {

        @Override
        public int compare(Row o1, Row o2) {
            // TODO Auto-generated method stub
            return 0;
        }
    };
}


@Override
public boolean canFilter(Predicate arg0, EvaluationContext arg1) {
    return true;
}

@Override
public boolean canXpath(Predicate arg0, EvaluationContext arg1) {
    return true;
}

@Override
public FacetExtractor getFacetExtractor(Predicate arg0, EvaluationContext arg1) {
    return null;
}

@Override
public String[] getOrderByProperties(Predicate arg0, EvaluationContext arg1) {
    return null;
}

@Override
public String getXPathExpression(Predicate arg0, EvaluationContext arg1) {
    return null;
}

@Override
public boolean includes(Predicate arg0, Row arg1, EvaluationContext arg2) {
    return true;
}

@Override
public boolean isFiltering(Predicate arg0, EvaluationContext arg1) {
    return false;
}       

}

I registered the predicate with: query.registerPredicateEvaluator("orderbytag", new OrderByTagPredicate()); And added it the map: map.put("orderbytag","xxx"); which is then used to create a PredicateGroup.

I've tried to debug by putting breakpoints in all the methods from the OrderByTagPredicate class, but it seems like the methods "getOrderByComparator(...)" never got called.

Any clue?

2 Answers 2

2

Resolved by adding the following into the map:

map.put("orderby","orderbytag");

The orderby clause was missing. Adding this clause makes AEM use the so-called PredicateEvalutor ordering method to be executed!

Sign up to request clarification or add additional context in comments.

Comments

0

When you just want to sort by a particular property, the easiest way to do it is to include an ordering predicate in the PredicateGroup you use to build your query. That way, you don't even need to worry about custom evaluators, since the default one will handle it for you.

Assuming you've already created "predicateGroup", and you want to sort by 'indexName' ascending, you would do:

Predicate orderPredicate = new Predicate(Predicate.ORDER_BY);
orderPredicate.set(Predicate.ORDER_BY, "@" + indexName);
orderPredicate.set(Predicate.PARAM_SORT, Predicate.SORT_ASCENDING);
predicateGroup.add(orderPredicate);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.