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

Avatar

Avatar

pjinfo

Avatar

pjinfo

pjinfo

24-09-2020

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

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar

Vijayalakshmi_S

MVP

Avatar

Vijayalakshmi_S

MVP

Vijayalakshmi_S
MVP

24-09-2020

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)

Answers (2)

Answers (2)

Avatar

Avatar

Magicr

Avatar

Magicr

Magicr

24-09-2020

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

Avatar

abhilakhpatre1

Avatar

abhilakhpatre1

abhilakhpatre1

24-09-2020

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