使用querybuilder在CQ5中进行不区分大小写的搜索

时间:2015-03-05 13:15:44

标签: cq5 predicate aem query-builder jcr

请建议如何在CQ5中使用querybuilder实现不区分大小写的搜索。我的代码如下......

paramMap.put("1_property", searchType);
paramMap.put("1_property.value", "%" + searchString + "%");
paramMap.put("1_property.operation", "like");
paramMap.put("2_property", "documentId");
paramMap.put("2_property.operation", "exists");
paramMap.put("3_orderby.sort", "asc");
paramMap.put("p.limit", "0");

searchType是节点属性 searchString是需要匹配的字符串

目前,它会进行区分大小写的搜索。我尝试了这里提到的解决方案 http://www.wemblog.com/2013/04/how-to-create-custom-query-predicate-in.html 它没有成功。

4 个答案:

答案 0 :(得分:3)

我遇到了同样的问题,并使用QueryBuilder找到了3个不区分大小写搜索的可能解决方案:

    您在上面提到的
  1. 自定义查询谓词

  2. 全文谓词。
    缺点:它很贪婪,会发现所有%your_search_query%匹配 详细信息如下:http://maxbarrass.blogspot.com/2014/05/jcr-predicate-operations-in-aem.html

  3. 节点名称谓词。
    这是解决方法,仅在您搜索 jcr:title 属性时才有效,因为在大多数情况下,nodename = lowercased和escaped jcr:title。
    因此,您可以搜索 nodename 而不是 jcr:titl e属性。

  4. 第三种方法对我有好处。

答案 1 :(得分:0)

使用AEM 6.2(我认为FP for 6.1)querybuilder现在支持通过orderby.case=ignore进行不区分大小写的排序。

答案 2 :(得分:0)

@alex order.case用于排序结果......

@Ignat和@David 使用Xpath的第四个选项:)

/jcr:root/etc/tags//element(*, cq:Tag)
[
(jcr:like(fn:lower-case(@jcr:title), '%projects%')) 
]

答案 3 :(得分:0)

唯一适用于我的解决方案是自定义谓词。

@Component(factory = "com.day.cq.search.eval.PredicateEvaluator/caseinsensitive")
public class CaseInsensitivePredicate extends AbstractPredicateEvaluator {


    @Override
    public String getXPathExpression(Predicate predicate, EvaluationContext context) {
        String property = predicate.get("caseinsensitive");
        String propertyValue = predicate.get("value");
        String operation = predicate.get("operation");

        String result;
        if ("like".equals(operation)) {
            result = "jcr:like(fn:lower-case(@" + property + "), '%" + propertyValue.toLowerCase() + "%')";
        } else {
            result = "fn:lower-case(@" + property + ") = '" + propertyValue.toLowerCase() + "'";
        }
        return result;
    }
}

对于您的QueryBuilder映射,您可以像这样使用它:

map.put("1_caseinsensitive", "propertyName");
map.put("1_caseinsensitive.value", "searchString");
map.put("1_caseinsensitive.operation", "like");
相关问题