• 使用querybuilder做忽略大小写查询的例子


    自定义Predicate:

    import com.day.cq.search.Predicate;
    import com.day.cq.search.eval.AbstractPredicateEvaluator;
    import com.day.cq.search.eval.EvaluationContext;
    import org.apache.felix.scr.annotations.Component;
    import org.slf4j.Logger;
    import org.slf4j.LoggerFactory;
    
    import javax.jcr.query.Row;
    
    @Component(
            metatype = true,
            factory = "com.day.cq.search.eval.PredicateEvaluator/caseinsensitive"
    )
    public class CaseInsensitiveLikePredicate extends AbstractPredicateEvaluator {
    
        private final Logger logger = LoggerFactory.getLogger(this.getClass());
    
        public static final String PROPERTY = "property";
        public static final String VALUE = "value";
        public static final String WILDCARD = "%";
    
        @Override
        public boolean includes(Predicate predicate, Row row, EvaluationContext context) {
            if (predicate.hasNonEmptyValue(PROPERTY)) {
                return true;
            }
            return super.includes(predicate, row, context);
        }
    
        @Override
        public String getXPathExpression(Predicate predicate, EvaluationContext context) {
            if (!predicate.hasNonEmptyValue(PROPERTY)) {
                return null;
            }
            if (predicate.hasNonEmptyValue(PROPERTY) && null == predicate.get(VALUE)) {
                return super.getXPathExpression(predicate, context);
            }
            if (predicate.hasNonEmptyValue(PROPERTY)) {
                predicate.get(VALUE);
                if (WILDCARD.equals(predicate.get(VALUE))) {
                    logger.info("Case Insensitive Query only has wildcard, ignoring predicate");
                    return "";
                }
                logger.info("jcr:like(fn:lower-case(" + predicate.get(PROPERTY) + "), '" + predicate.get(VALUE).toLowerCase() + "')");
                return "jcr:like(fn:lower-case(" + predicate.get(PROPERTY) + "),'" + predicate.get(VALUE).toLowerCase() + "')";
            }
            return null;
        }
    }

    使用predicate:

    if (!StringUtils.isBlank(q)) {
                map.put("group.p.or", "true");
                map.put("group.1_caseinsensitive.value", "%" + q + "%");
                map.put("group.1_caseinsensitive.property", "jcr:title");
                map.put("group.2_caseinsensitive.value", "%" + q + "%");
                map.put("group.2_caseinsensitive.property", "text1");
                map.put("group.3_caseinsensitive.value", "%" + q + "%");
                map.put("group.3_caseinsensitive.property", "text2");
            }

    参考 https://forums.adobe.com/thread/2326696

     
  • 相关阅读:
    在WPF中添加Windows Form控件
    LIST对象排序问题
    C# TreeView树节点上下移动
    C# listbox的上下移动,拖动排序,两个listbox相互拖动
    Nmap 扫描并生成HTML报告
    Windows 10 系统精简方案参考
    Windows10 子系统 Ubuntu安装
    VS2012 RC页面检查器
    新增功能.NET 框架 4.5 RC
    PowerPoint Storyboarding:Visual Studio 2012 RC带给开发者的秘密杀器
  • 原文地址:https://www.cnblogs.com/blogkevin/p/10690241.html
Copyright © 2020-2023  润新知