Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.

AEM 6.2 "fn:lowercase" is not working

Avatar

Level 3

Dear Team,  

. How I can incoperate case sensitive search in AEM 6.2 with predicates.

I have tried below mentioned code unfortunately it doesn't work for me.But it is working fine in  5.6.1

Predicate authorNamePredicate = new Predicate("@authorName", "property");
authorNamePredicate.set(JcrPropertyPredicateEvaluator.OPERATION, JcrPropertyPredicateEvaluator.OP_LIKE);
                 authorNamePredicate
                     .set("property", "@fn:lower-case(@" + JcrConstants.JCR_CONTENT + "/" + "authorName" + ")");
                 authorNamePredicate.set("value", "%" + author.toLowerCase() + "%");
                 authorgroup.add(authorNamePredicate);

 

@fn:lower-case(" - is converted to fn:lower-case_x0028_  this is creating issue in AEM 6.2

 "/jcr:root/content/geo//*[@jcr:primaryType = 'cq:Page' and not(jcr:content/@hideInNav) and jcr:content/@jcr:title != 'Master Article' and jcr:like(fn:lower-case_x0028_/jcr:content/@authorName_x0029_, 'soumik dey')]/rep:excerpt(.) order by jcr:content/@cq:lastModified descending" This is the query it generating 

 

Thanks!

Unnikrishnan

10 Replies

Avatar

Administrator

Hi 

Please have a look at this forum thread:-

Link:- http://help-forums.adobe.com/content/adobeforums/en/experience-manager-forum/adobe-experience-manage...

//  we never officially supported functions.  Hence not a bug. You have to file enhancement request to support xpath function. it is a known problem with the OAK repository

Please create a day care ticket for this.

 

Reference post telling about toupper/toLower in AEM :- http://www.wemblog.com/2013/04/how-to-create-custom-query-predicate-in.html

// You need to create a create custom query predicate.

I hope this would help you.

~kautuk



Kautuk Sahni

Avatar

Level 3

Thank you  kautuk , I have tried custom predicate in this case it throwing same error like "java.text.ParseException: Query". Am using  fn:lowercase with predicates not in query.  I have raised to  Adobe team internally  and they created Day care ticket for that. Can you confirm  xpath queries are not supported in AEM 6.2 ? It will helpful for us . Our search concept working with predicates, so we need to change entire search code if it not supported.

Thanks!, 

Unnikrishnan

Avatar

Level 1

Hi Kirshnan,

Is this issue solved? I am also facing the same issue, let me know creating the day care tickets helped?

Thanks,

Ravi

Avatar

Administrator

Workaround: converted the query to SQL2 version in our code, this would work

Please create day care ticket!!

-Kautuk



Kautuk Sahni

Avatar

Level 1

Thanks Kautuk, will raise a ticket and see if we can convert our search module to use sql2.

Avatar

Level 10

This is not the exact code which you would need but should help you to proceed.


import com.day.cq.search.Predicate;
import com.day.cq.search.eval.AbstractPredicateEvaluator;
import com.day.cq.search.eval.EvaluationContext;
import org.apache.felix.scr.annotations.Component;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.jcr.query.Row;

/**
* Custom case insensitive predicate for like operation
* caseinsensitive.property=jcr:content/@jcr:title
* caseinsensitive.value= queryString %
*
*/
@Component(
metatype = false,
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 = "%";
@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;
}
}

Avatar

Level 1

Thanks edubey, appreciate your support. The problem that I have to use this approach is that our query is slightly complexed with multiple properties queried. It looks like below, With your code approach, I cant just use

caseinsensitive.property=jcr:content/@jcr:title

* caseinsensitive.value= queryString %.

Any idea how we can tackle this?

fulltext=tax

mainasset=true

1_group.1_group.path=/content/project_name

2_group.1_group.type=cq:Page

2_group.1_group.p.or=true

1_group.2_group.path=/content/dam/project_name

1_group.p.or=true

2_group.2_group.type=dam:Asset

2_group.p.or=true

2_group.2_group.1_property=jcr:content/metadata/dc:format

2_group.2_group.1_property.1_value=application/pdf

2_group.2_group.5_group.2_property.operation=like

2_group.2_group.5_group.2_property=jcr:content/metadata/dc:description

2_group.2_group.5_group.2_property.1_value=%tax%

2_group.2_group.5_group.3_property.operation=like

2_group.2_group.5_group.3_property=jcr:content/metadata/cq:tags

2_group.2_group.5_group.3_property.1_value=%tax%

2_group.2_group.5_group.4_property.operation=like

2_group.2_group.5_group.4_property=jcr:content/metadata/dc:title

2_group.2_group.5_group.4_property.1_value=%tax%

2_group.2_group.5_group.p.or=true

3_group.p.and=true

3_group.property=jcr:content/hideInSearch

3_group.property.operation=not

5_group.1_relativedaterange.property=jcr:content/cq:lastModified

5_group.1_relativedaterange.upperBound=0

2_group.1_group.2_property=jcr:content/contentType

2_group.1_group.2_property.1_value=Article

2_group.1_group.1_property=jcr:content/cq:tags

2_group.1_group.1_property.1_value=%tax%

2_group.1_group.1_property.operation=like

Avatar

Level 3

Thanks you ,

It is working .i have already implemented in my project and i forgot to mentioned here .. 

Avatar

Level 1

Hi Devakrishna

I am facing similar issue in my Code. Could you please explain how you resolved it?