Wildcard Case Insensitive AEM Query Builder | Community
Skip to main content
touseefk2181136
Level 3
September 2, 2024
Solved

Wildcard Case Insensitive AEM Query Builder

  • September 2, 2024
  • 2 replies
  • 1201 views

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;

@8220494(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";

@9944223
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 + "'";
}
}

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by touseefk2181136

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 + "')";
}
}

2 replies

pulkitvashisth
Community Advisor
Community Advisor
September 2, 2024

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/deploying/queries-and-indexing


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.

 

 

touseefk2181136
Level 3
September 2, 2024

@pulkitvashisth thanks for your message. I don't want to perform fulltext search. Search on a specific property

touseefk2181136
touseefk2181136AuthorAccepted solution
Level 3
September 2, 2024

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 + "')";
}
}