Expand my Community achievements bar.

SOLVED

search inside a page content and the content of the content fragment used inside the page

Avatar

Level 1

Hello,

 

I have a requirement to search any content inside all the pages of a website. I have written a query like SELECT * FROM [cq:PageContent] AS content WHERE ISDESCENDANTNODE('/content/pathoftheproject') and contains(content.*, 'search_keyword') This query is searching for a keyword which is within the page content. But most of the page content is residing inside the content fragment which is referred in the page. The seach query is not performing search within the content of the page content. Is there any way that I can alter the query or write custom code to search inside the page content and the content fragment referred inside the page content?

 

Thanks

 

pjinfo

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @pjinfo,

Below is the sample query predicate set for 2 queries

One to do a full text search on Page and content fragment path (OR condition between page and fragment)

3_group.1_group.path=/content/dam/learnings/contentfragments
3_group.1_group.type=dam:Asset
3_group.2_group.path=/content/learnings
3_group.2_group.type=cq:PageContent
3_group.p.or=true
fulltext=searchtext // search param
p.limit=-1

Second to bring in the pages where the fragment (acquired in result of first query execution) is authored

path=/content/learnings
type=nt:unstructured
1_property=sling:resourceType
1_property.value=learnings/components/content/contentfragment
2_property=fragmentPath
2_property.value=/content/dam/learnings/contentfragments/sample-cf-web
p.limit=-1

Sample code with implementation using Query Builder API is added to my GITHUB repo 

Assumptions:

  • Content Fragments authored in site pages are from common project specific path like - /content/dam/customproject/contentfragments
    • If this path varies, might need additional change in logic accordingly. This is because search param might be in image/video/doc/ any other related asset you have as part of project specific DAM folder
  • Page root is site specific content path - /content/customproject
  • Content fragment component used in site pages is project specific say -customproject/components/content/contentfragment (Used in second query. If it is not consistent across pages, can remove the respective predicate and fragmentPath property check alone should be fine)

View solution in original post

4 Replies

Avatar

Level 2

I had similar requirement of searching the content inside content fragment inside page.

 

I'm not sure below will help you but I'm trying to just help :

 

There will be different scenarios or requirements. One of it is:

Scenario 1 : You want the pages in which there is content fragment having search keyword 'hello_world'

 

You can go through below points and try to implement in this way:

1) Content fragments are of type dam:Asset

 

2) Refine your query to search in Dam for the type dam:Asset and provide your properties and values to be searched .

 

3) It will provide you the let's say 5 content fragments like .. /content/dam/contentfragmentpaths

 

4) You can run one more query ( or you can use sub or inner query sql2 )  to find out the pages in which these 5 content fragments are referred or authored (in page)

 

Hope it's helpful.

 

Thanks

Abhishek Lakhpatre

 

 

Avatar

Level 1
I got your point and this is what I was thinking of, but do you have any implementation sample which you can share. Atleast I need a query in which a subquery can also be passed.

Avatar

Level 7

My question to key word contains is similar to yours. See https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/sql2-query-with-contains-d.... Will it help if you use the like operator instead of contains?

Avatar

Correct answer by
Community Advisor

Hi @pjinfo,

Below is the sample query predicate set for 2 queries

One to do a full text search on Page and content fragment path (OR condition between page and fragment)

3_group.1_group.path=/content/dam/learnings/contentfragments
3_group.1_group.type=dam:Asset
3_group.2_group.path=/content/learnings
3_group.2_group.type=cq:PageContent
3_group.p.or=true
fulltext=searchtext // search param
p.limit=-1

Second to bring in the pages where the fragment (acquired in result of first query execution) is authored

path=/content/learnings
type=nt:unstructured
1_property=sling:resourceType
1_property.value=learnings/components/content/contentfragment
2_property=fragmentPath
2_property.value=/content/dam/learnings/contentfragments/sample-cf-web
p.limit=-1

Sample code with implementation using Query Builder API is added to my GITHUB repo 

Assumptions:

  • Content Fragments authored in site pages are from common project specific path like - /content/dam/customproject/contentfragments
    • If this path varies, might need additional change in logic accordingly. This is because search param might be in image/video/doc/ any other related asset you have as part of project specific DAM folder
  • Page root is site specific content path - /content/customproject
  • Content fragment component used in site pages is project specific say -customproject/components/content/contentfragment (Used in second query. If it is not consistent across pages, can remove the respective predicate and fragmentPath property check alone should be fine)