AEM 6.2 "fn:lowercase" is not working | Community
Skip to main content
Unnikrishnankv
Level 3
Jan 3, 2017 4:28 AM UTC

AEM 6.2 "fn:lowercase" is not working

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

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

10 replies

edubey
Level 10
Jan 16, 2018 3:23 PM UTC

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;
}
}
Translate
New Participant
Jan 16, 2018 10:02 PM UTC

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

Translate
kautuk_sahni
Employee
Jan 3, 2017 6:03 AM UTC

Hi 

Please have a look at this forum thread:-

Link:- http://help-forums.adobe.com/content/adobeforums/en/experience-manager-forum/adobe-experience-manager.topic.html/forum__scgy-we_r_runningaquery.html

//  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

Translate
Kautuk Sahni
Unnikrishnankv
Level 3
Jan 3, 2017 7:32 AM UTC

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

Translate
New Participant
Jan 16, 2018 4:06 AM UTC

Hi Kirshnan,

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

Thanks,

Ravi

Translate