Expand my Community achievements bar.

SOLVED

Writing Case Insensitive Query in Query Builder

Avatar

Level 4

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 ?

1 Accepted Solution

Avatar

Correct answer by
Level 6

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

View solution in original post

4 Replies

Avatar

Level 4

Please check this link 

https://stackoverflow.com/questions/20285579/querying-case-insensitive-paths-with-sql2-isdescendantn... 

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

Avatar

Community Advisor

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.

 

Avatar

Correct answer by
Level 6

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

Avatar

Level 4

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

Thanks @rampai for the solution!