2016-04-21 24 views
4

我試圖實現PredicateEvaluator僅用於訂購目的 - 無過濾。AEM查詢生成器:實現PredicateEvaluator僅用於訂購

於是我開始:

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; 
}  

}

我註冊與謂詞: query.registerPredicateEvaluator( 「orderbytag」,新OrderByTagPredicate()); 並添加了地圖:map.put(「orderbytag」,「xxx」);然後用它來創建一個PredicateGroup。

我試着通過在OrderByTagPredicate類的所有方法中放入斷點來進行調試,但它好像沒有調用方法「getOrderByComparator(...)」。

任何線索?

回答

1

通過添加以下到地圖解決:

map.put( 「排序依據」, 「orderbytag」);

orderby子句丟失。添加此子句使得AEM使用所謂的PredicateEvalutor排序方法來執行!

0

當您只想按特定屬性進行排序時,最簡單的方法是在您用於構建查詢的PredicateGroup中包含排序謂詞。這樣,你甚至不需要擔心自定義評估器,因爲默認的評估器會爲你處理它。

假定你已經創建「predicateGroup」,並且要通過「INDEXNAME」升序進行排序,你會怎麼做:

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