Writing Case Insensitive Query in Query Builder | Community
Skip to main content
Ankan_Ghosh
January 16, 2023
Solved

Writing Case Insensitive Query in Query Builder

  • January 16, 2023
  • 3 replies
  • 3495 views

How do I write a case insensitive query in AEM ? For example we want to fetch pages based on the jcr:title of a page and the actual jcr:title value is "Page 2", but the user searches for "paGe 2" and in this case we don't get any results. But I want to fetch the page with jcr:title "Page 2" . How do we achieve this functionality ?

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 rampai

Hi @ankan_ghosh ,

 

You can go for something like below for Query Builder.

 

path=/content/wknd
property=jcr:content/@jcr:title
property.operation=equalsIgnoreCase
property.value=MaGAZine

 

This is documented here.

JcrPropertyPredicateEvaluator (The Adobe AEM Quickstart and Web Application.)

 

operation"equals" for exact match (default), "unequals" for unequality comparison, "like" for using the jcr:like xpath function (optional), "not" for no match (eg. "not(@prop)" in xpath, value param will be ignored), "exists" for existence check (value can be true - property must exist, the default - or false - same as "not") , "equalsIgnoreCase" for case insensitive match, "unequalsIgnoreCase" for case insensitive unequality comparison.

 

Other approaches have been shared in earlier replies which is to convert to lowercase before searching or use JCR-SQL2.

 

Thanks,

Ram

3 replies

January 16, 2023

Please check this link 

https://stackoverflow.com/questions/20285579/querying-case-insensitive-paths-with-sql2-isdescendantnode-in-cq5 

And also try

if you are using java ,you can convert search value to lowercase and then pass to sql query to fetch the results.

Thanks

Anmol_Bhardwaj
Community Advisor
Community Advisor
January 16, 2023

Hi @ankan_ghosh ,

 

If you're just looking to search through jcr:title and node title, I would suggest you to use fullText in Query Builder with a wild card (*), it takes care of case sensitive , and includes both capital and small.

 

Now, if you are using the search term dynamically, I assume you are building query through the back end. As, if you're searching for a particular term, you can just group 2 queries.

So, what I would suggest is, you should covert the term to lower case in the back-end through string manipulations and that way you , most definitely would get the right result everytime.

 

rampai
Community Advisor
rampaiCommunity AdvisorAccepted solution
Community Advisor
January 16, 2023

Hi @ankan_ghosh ,

 

You can go for something like below for Query Builder.

 

path=/content/wknd
property=jcr:content/@jcr:title
property.operation=equalsIgnoreCase
property.value=MaGAZine

 

This is documented here.

JcrPropertyPredicateEvaluator (The Adobe AEM Quickstart and Web Application.)

 

operation"equals" for exact match (default), "unequals" for unequality comparison, "like" for using the jcr:like xpath function (optional), "not" for no match (eg. "not(@prop)" in xpath, value param will be ignored), "exists" for existence check (value can be true - property must exist, the default - or false - same as "not") , "equalsIgnoreCase" for case insensitive match, "unequalsIgnoreCase" for case insensitive unequality comparison.

 

Other approaches have been shared in earlier replies which is to convert to lowercase before searching or use JCR-SQL2.

 

Thanks,

Ram

Ankan_Ghosh
January 16, 2023

This is exactly what I was asking for. The query worked.

Thanks @rampai for the solution!