I want to search a text in lower case in query builder api in aem. For example my node is /conent/mydata/stores. It has store id nodes, each store id node has store information in properties like storeName etc. I need to search store by storeName using query builder api. The search should work lower case as well as upper case. I have created following custom predicate but it works with equals text while I need wildcard search with like operation, I tried to create another custom predicate 'likeIgnoreCase' but is doesn't work. Kindly guide if someone has idea about it.
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;
@component(factory = "com.day.cq.search.eval.PredicateEvaluator/equalsIgnoreCase")
public class CaseInsensitiveEquals extends AbstractPredicateEvaluator {
private static final Logger log = LoggerFactory.getLogger(CaseInsensitiveEquals.class);
static final String PREDICATE_PROPERTY = "property";
@Override
public String getXPathExpression(Predicate predicate, EvaluationContext context) {
String property = predicate.get(PREDICATE_PROPERTY);
String value = predicate.get("value").toLowerCase();
return "fn:lower-case(@" + property + ") = '" + value + "'";
}
}
Solved! Go to Solution.
Topics help categorize Community content and increase your ability to discover relevant content.
Views
Replies
Total Likes
Ok I found following solution and it is working perfectly.
@Component(factory = "com.day.cq.search.eval.PredicateEvaluator/likeIgnoreCase")
public class CaseInsensitiveLike extends AbstractPredicateEvaluator {
private static final Logger log = LoggerFactory.getLogger(CaseInsensitiveLike.class);
static final String PREDICATE_PROPERTY = "property";
@Override
public String getXPathExpression(Predicate predicate, EvaluationContext context) {
String property = predicate.get(PREDICATE_PROPERTY);
String value = predicate.get("value").toLowerCase();
return "jcr:like(fn:lower-case(@" + property + "), '" + value + "')";
}
}
Hi @touseefk2181136
From what I could understand you wanted that you should be able to do full-text search with case insensitivity.
For that you need to modify your oak-index that is being used in your project.
If not custom then cqPageLucene would be invoked based on indexed properties.
You need to create following structure of the oak index to add node LowerCase to enable case insensitivity as below.
Documentation link : https://experienceleague.adobe.com/en/docs/experience-manager-65/content/implementing/deploying/depl...
After this when you have re-indexed above Oak Index,
and when you do full-text search, case insensitive matches should also come up in results.
@pulkitvashisth thanks for your message. I don't want to perform fulltext search. Search on a specific property
Ok I found following solution and it is working perfectly.
@Component(factory = "com.day.cq.search.eval.PredicateEvaluator/likeIgnoreCase")
public class CaseInsensitiveLike extends AbstractPredicateEvaluator {
private static final Logger log = LoggerFactory.getLogger(CaseInsensitiveLike.class);
static final String PREDICATE_PROPERTY = "property";
@Override
public String getXPathExpression(Predicate predicate, EvaluationContext context) {
String property = predicate.get(PREDICATE_PROPERTY);
String value = predicate.get("value").toLowerCase();
return "jcr:like(fn:lower-case(@" + property + "), '" + value + "')";
}
}
Views
Likes
Replies