AEM QueryBuilder API: Where do I put my custom created predicate?
I am using a custom predicate which is: https://github.com/arunpatidar02/aem63app-repo/blob/master/java/CaseInsensitiveLikePredicate.java
I want to test it in local AEM server and so want to know what's the process of integrating this predicate to my local AEM author instance? I have a folder crx-quickstart am I supposed to tap into that? Please help!
I tried following: https://experienceleague.adobe.com/docs/experience-manager-65/developing/platform/query-builder/implementing-custom-predicate-evaluator.html?lang=en
However documentation only talks about creating the predicate and not about how to deploy it to your local AEM instance. Here are steps I followed:
1. Clone the Predicate Repository (https://github.com/Adobe-Marketing-Cloud/aem-search-custom-predicate-evaluator)
2. Change the Code in
src/main/java/com/adobe/aem/docs/search/ReplicationPredicateEvaluator.java
to
package com.aem.community.core.utils;
import com.day.cq.search.Predicate;
import com.day.cq.search.eval.AbstractPredicateEvaluator;
import com.day.cq.search.eval.EvaluationContext;
import org.osgi.service.component.annotations.Component;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.jcr.query.Row;
/**
* Custom case insensitive predicate for like operation e.g.
* caseinsensitive.property=jcr:content/@jcr:title
* caseinsensitive.value=queryString %
*
*/
@Component(factory = "com.day.cq.search.eval.PredicateEvaluator/caseinsensitive")
public class CaseInsensitiveLikePredicate extends AbstractPredicateEvaluator {
public static final String PROPERTY = "property";
public static final String VALUE = "value";
public static final String WILDCARD = "%";
protected final Logger logger = LoggerFactory.getLogger(this.getClass());
@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;
}
}
3. run the command: `mvn clean install -PautoInstallSinglePackage` from CLI. ( I am using AEM 6.5) which results in
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] error: Source option 5 is no longer supported. Use 6 or later.
[ERROR] error: Target option 1.5 is no longer supported. Use 1.6 or later.
After performing the following steps, I have three questions:
1. In step 2 where I add my custom predicate, do I also need to change anything in pom.xml to make sure it gets correctly configured?
2. After having my custom predicate, what am I supposed to do to load or deploy in my AEM localhost:4502 for testing?
3. Looking at the code I shared which I took from one of the github repos (https://github.com/arunpatidar02/aem63app-repo/blob/master/java/CaseInsensitiveLikePredicate.java) would this also cover the case where I want to use this predicate in groups or would it work standalone only? Here's an example:
I know this will work:
* caseinsensitive.property=jcr:content/@jcr:title
* caseinsensitive.value=queryString %
but would this work too?
1_group.1_caseinsensitive.property=jcr:content/@jcr:title
1_group.1_caseinsensitive.value=queryString %
