AEM xpath query with contains for a certain cq page aem6.5 | Community
Skip to main content
srinivas_chann1
Level 7
June 6, 2022
Solved

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

  • June 6, 2022
  • 1 reply
  • 4941 views

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/
@2107369 = '%battery%'))
and (jcr:contains(jcr:content/root/container/node2/_text/
@2107369, '%baTTery%'))
]
order by 
@6655266: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

Best answer by DEBAL_DAS

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

 

1 reply

srinivas_chann1
Level 7
June 7, 2022

Hi,

 

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

 

Regards,

Srinivas

 

 

DEBAL_DAS
DEBAL_DASAccepted solution
New Member
June 7, 2022

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, Senior AEM Consultant
this-that-the-otter
Level 4
March 11, 2025

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 @6655266: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.