Expand my Community achievements bar.

Adobe Summit 2025: AEM Session Recordings Are Live! Missed a session or want to revisit your favorites? Watch the latest recordings now.
SOLVED

AEM xpath query with contains for a certain cq page aem6.5

Avatar

Level 8

Hi ,

 

Could some one provide inputs as how to generate jcr:contains query using xpath , I would need case insensitive search but only limiting to certain node paths 

 

I am getting the below 

/jcr:root/content/project/us/en//Product_Reference_Guide//element(*, cq:Page)
[
((jcr:content/root/container/node1/_text/
@text = '%battery%'))
and (jcr:contains(jcr:content/root/container/node2/_text/
@text'%baTTery%'))
]
order by 
@jcr:score descending

 

I am using the below in querydebug.html

 

path=/content/project/us/en/Product_Reference_Guide

orderby=@jcr:score

orderby.sort=desc

type=cq:Page

group.1_property=jcr:content/root/container/node1/_text/@text

group.1_property.1_value=%battery%

fulltext.relPath=jcr:content/root/container/node2/_text/@text

fulltext=%baTTery%

 

 

I have used fulltext.relPath  which generated the jcr:contains but cannot use it on other path 

when I use group.1_property  it does not again generate jcr:contains

 

How to solve this. Any inputs will be helpful.

 

Regards,

Srinivas

1 Accepted Solution

Avatar

Correct answer by
Employee Advisor

are you looking for something like the below one -

 

path=/content/we-retail/language-masters/en
type=cq:Page
fulltext=experience
fulltext.relPath=jcr:content
1_property=jcr:content/cq:lastReplicationAction
1_property.value=Activate
2_property=jcr:content/clientlibsJsHead
2_property.value=dam.gui.coral.brandportal.configurations
p.limit=-1

DEBAL_DAS_0-1654577874413.png

 

View solution in original post

8 Replies

Avatar

Level 8

Hi,

 

Any inputs from any one as how to generate jcr:contains query using xpath for multiple properties and certain search text

 

Regards,

Srinivas

 

 

Avatar

Correct answer by
Employee Advisor

are you looking for something like the below one -

 

path=/content/we-retail/language-masters/en
type=cq:Page
fulltext=experience
fulltext.relPath=jcr:content
1_property=jcr:content/cq:lastReplicationAction
1_property.value=Activate
2_property=jcr:content/clientlibsJsHead
2_property.value=dam.gui.coral.brandportal.configurations
p.limit=-1

DEBAL_DAS_0-1654577874413.png

 

Avatar

Level 8

Thanks for input .

 

I need to search from around 6 nodes from cq: page and it must contain jcr:contains for all the search as i would to search the same text under those nodes. 

 

Any inputs as how could this be done

 

/jcr:root/content/apps/us/en/Product_Reference_Guide//element(*, cq:Page)

    [

    (

              (jcr:contains(jcr:content/root/container/node1/_text/@text, '%Battery%'))

    or (jcr:contains(jcr:content/@jcr:title, '%Battery%'))

    or (jcr:contains(jcr:content/root/container/node2/_text/@text, '%Battery%'))

    or (jcr:contains(jcr:content/root/container/node3/_text/@text, '%Battery%'))

   )

    ]

    order by @jcr:score descending

 

Regards,

Srinivas

Avatar

Community Advisor

Addition to @DEBAL_DAS 

Use case insensitive like below using LOWER function

 

 "SELECT * FROM mix:title WHERE LOWER(jcr:title) = 'casesensitive'";

 

Arun Patidar

AEM LinksLinkedIn

Avatar

Community Advisor

in addition to @arunpatidar  @DEBAL_DAS  

 

refer https://experienceleague.adobe.com/docs/experience-manager-65/developing/platform/query-builder/quer...

for query builder predicate reference.

Himanshu Jain

Avatar

Employee Advisor

Are these 6 nodes available under a specific page?

If you are expecting to deal with multiple pages then node name like node2 , node3 might differ from one page to another page. 

Then we need to understand content node structure first.

Avatar

Level 8

Hi,

 

I was able to get jcr:contains with or with below .Thanks for the help

 

path=/content/apps/us/en/Product_Reference_Guide

orderby.sort=desc

orderby=@jcr:score

type=cq:Page

group.1_fulltext.relPath=jcr:content/root/container/node1/_text/@text

group.1_fulltext=%Battery%

group.2_fulltext.relPath=jcr:content/jcr:title

group.2_fulltext=%Battery%

group.3_fulltext.relPath=jcr:content/root/container/node2/note/_text/@text

group.3_fulltext=%Battery%

group.p.or=true

 

This gave the below query

/jcr:root/content/tcm/us/en/mobile-computers/handheld/tc5-series/TC57_Product_Reference_Guide//element(*, cq:Page)

[

(jcr:contains(jcr:content/root/container/node1/_text/@text, '%Battery% ')

or jcr:contains(jcr:content/@jcr:title, '%BaTTery%')

or jcr:contains(jcr:content/root/container/node2/note/_text/@text, '%Battery%')

)

]

order by @jcr:score descending

@srinivas_chann1 This was helpful for me. I was attempting to optimize an XPATH query one of our page's components incorporates as a node / property. It was using: 

 

//content/foo/en/bar/*[jcr:contains(@type, "*")]

 

I found that * caused a traversal so hoped to OR all the valid values for "type" (and your syntax above was a good reference) - unfortunately using ORs also caused a traversal (though selecting just 1 value did not), but when checking if a different property contained 1 specific value: 

 

//content/foo/en/bar/*[jcr:contains(@url, "http")]

 

the traversal also disappeared. Unfortunately, this query was not ideal for the page in question.  One other thing in your response looked different from my query, instead of using:

 

//content

 

 as the root, you use: 

 

/jcr:root/content

 

and this change seems also to prevent traversal in my case, even when using: 

 

//content/foo/en/bar/*[jcr:contains(@type, "*")]

 

I haven't tried using ORs again. Perhaps they will also now work without traversal because of the "jcr:root" specification - but for the moment, there's no need to try as using "jcr:root" seems to fix the issue for me.  

I wonder what the difference between

 

//content

 

and 

 

/jcr:root/content

 

is? I've seen the former syntax quite a bit in AEM.