Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.

Does AEM Query builder API allow searching the Content Fragment Core component's content included within a Page?

Avatar

Level 2

Hi All,

Please advise if AEM Query builder API supports searching of Content Fragment's (Adobe's Core component) content included within a Page.

I have added a Content Fragment core component on an empty content page (newly created) and authored all the required values for the component including fragmentPath. The component renders as expected and displays the Content Fragment data. However, when I tried searching for the data within content fragment using the following sample queries through Query Builder Debugger, it did not return any results. I am not sure if any new predicates are needed to enable the search functionality for content fragments.

Query Builder query 1:

type=cq:Page

path=<search path>(e.g., /content/we-retail/us/en)

fulltext=<searchterm> (e.g., winter)

Query Builder query 2:

type=cq:Page

path=<search path>(e.g., /content/we-retail/us/en)

fulltext=<searchterm> (e.g., winter)

contentfragment

AEM Version: 6.3.3.0

AEM Core Components Version: 2.5.0

Any advise or guidance would be greatly appreciated. Thank you in advance.

kautuk sahni  smacdonald2008

21 Replies

Avatar

Employee

You can try a query similar to:

type=nt:unstructure

path=/content/we-retail/us

1_group.1_property=sling:resourceType

1_group.1_property.value=weretail/components/content/contentfragment

fulltext=winter

Avatar

Level 2

berliant​ Thanks for your prompt reply!

However, the provided query does not seem to work (no search results) for the specified scenario (Trying to search content fragment component data included within page).

type=nt:unstructured

path=/content/we-retail/us/en

1_group.1_property=sling:resourceType

1_group.1_property.value=weretail/components/content/contentfragment

fulltext=winter

Please note that the actual content fragment data is not being saved within page node structure as it is only being referenced through the "fragmentPath" property. Also, the core content fragment component has already been proxied under we-retail directory/project - "/apps/weretail/components/content/contentfragment". Let me know if you have any questions.

Avatar

Employee

Sorry for a typo in my previous post. Here is the query, that works on my test env and returns a page where a Content Fragment includes a word "winter":

path=/content/we-retail/us

type= cq:Page

group.p.and

group.1_fulltext=winter

group.2_fulltext=contentfragment

1836677_pastedImage_0.png

Avatar

Level 2

berliant​ Thanks again! But the updated query provided also does not seem to work (no search results yet).

I have authored a test page under "/content/we-retail/us" containing Core Content Fragment component which includes a word "career". Are you using a proxied Core "Content Fragment" component or out of the box (General) "Content Fragment" component?

Screen Shot 2019-09-23 at 3.21.24 PM.png

Please note that the search works appropriately with OOB (General) Content Fragment already. My question is specific to the latest Core Content Fragment Component.

I am currently using AEM 6.3.3.0 with AEM Core Components v2.5.0 installed. Could you please let me know which version of AEM Core components has been installed in your test environment and the AEM version being used.

Avatar

Employee

My test was done on the same version.

1836678_pastedImage_0.png

1836679_pastedImage_1.png

As you have "contentfragment" in JCR I don't think it matters what component you are extending.

It searches on the keyword and the fact that the page has CF.

Avatar

Level 2

berliant​ Really appreciate your prompt response.

Sorry, I forgot to mention that I have been trying to search for "Structured Content Fragments" created using custom Content Fragment Model. The search had been working appropriately for a simple content fragment but does not seem to work with the structured content fragments.

Find below the structured content fragment included on a test page. The main difference I could see is that the "text" property ( which is created automatically for simple fragments) containing the fragment data/text is not being created within component node as multiple model elements are being referenced in this case under "master" variation. The search may not be working as the text is not attached to the page node and is just being referenced through "fragmentPath" property.

Screen Shot 2019-09-23 at 5.06.08 PM.png

Find below the structured content fragment created with a new Content Fragment Model containing "name", "age", "sport", "about" elements.

Screen Shot 2019-09-23 at 5.13.25 PM.png


Please review and advise if Query builder API supports searching the structured content fragments as well or just the simple content fragments.

Avatar

Employee

You need to index your custom properties: "about", "name", "age" etc.

The query that I provided executes the plan:

PLAN: [cq:Page] as [a] /* lucene:cqPageLucene(/oak:index/cqPageLucene) +(+:fulltext:winter +:fulltext:contentfragment) +:ancestors:/content/we-retail/us ft:("winter" "contentfragment") where (contains([a].[*], 'winter')) and (contains([a].[*], 'contentfragment')) and (isdescendantnode([a], [/content/we-retail/us])) */

It means that you need to edit cqPageLucene index by adding a dedicated property. For example, for "about" it should be something like:

1836887_pastedImage_0.png

Make sure that you re-index /oak:index/cqPageLucene prior of testing the query.

Avatar

Level 2

berliantThanks again for your response.

I have added the "about" property as specified under "cqPageLucene" and also re-indexed the "/oak:index/cqPageLucene" index. However, the debugger does not return any results yet. I have also tried restarting the AEM instance and re-indexing again.

Could you please review and let me know if any additional configurations are needed.

Screen Shot 2019-09-24 at 10.43.57 AM.png

Screen Shot 2019-09-24 at 10.53.13 AM.png

Find below the "Query Explanation" details.

Indexes Used

cqPageLucene(/oak:index/cqPageLucene)

Execution Time

Total time: 2 ms

Query execution time: 1 ms

Get nodes time: 1 ms

Execution Plan

[cq:Page] as [a] /* lucene:cqPageLucene(/oak:index/cqPageLucene) +(+:fulltext:career +:fulltext:contentfragment) +:ancestors:/content/we-retail/us ft:("career" "contentfragment") where (contains([a].[*], 'career')) and (contains([a].[*], 'contentfragment')) and (isdescendantnode([a], [/content/we-retail/us])) */

Logs

Parsing xpath statement: explain /jcr:root/content/we-retail/us//element(*, cq:Page)[(jcr:contains(., 'career') and jcr:contains(., 'contentfragment'))]

XPath > SQL2: explain select [jcr:path], [jcr:score], * from [cq:Page] as a where contains(*, 'career') and contains(*, 'contentfragment') and isdescendantnode(a, '/content/we-retail/us') /* xpath: /jcr:root/content/we-retail/us//element(*, cq:Page)[(jcr:contains(., 'career') and jcr:contains(., 'contentfragment'))] */

Literal used

Attempting optimisation

cost using filter Filter(query=explain select [jcr:path], [jcr:score], * from [cq:Page] as a where contains(*, 'career') and contains(*, 'contentfragment') and isdescendantnode(a, '/content/we-retail/us') /* xpath: /jcr:root/content/we-retail/us//element(*, cq:Page)[(jcr:contains(., 'career') and jcr:contains(., 'contentfragment'))] */ fullText="career" "contentfragment", path=/content/we-retail/us//*)

cost for reference is Infinity

cost for property is Infinity

cost for nodeType is Infinity

Evaluating plan with index definition Lucene Index : /oak:index/slingeventJob

No applicable IndexingRule found for any of the superTypes [nt:hierarchyNode, cq:Page, nt:base, mix:created]

Evaluating plan with index definition Lucene Index : /oak:index/versionStoreIndex

Evaluating plan with index definition Lucene Index : /oak:index/cqTagLucene

No applicable IndexingRule found for any of the superTypes [nt:hierarchyNode, cq:Page, nt:base, mix:created]

Evaluating plan with index definition Lucene Index : /oak:index/workflowDataLucene

No applicable IndexingRule found for any of the superTypes [nt:hierarchyNode, cq:Page, nt:base, mix:created]

Evaluating plan with index definition Lucene Index : /oak:index/socialLucene

No applicable IndexingRule found for any of the superTypes [nt:hierarchyNode, cq:Page, nt:base, mix:created]

Evaluating plan with index definition Lucene Index : /content/oak:index/enablementResourceName

Evaluating plan with index definition Lucene Index : /oak:index/authorizables

No applicable IndexingRule found for any of the superTypes [nt:hierarchyNode, cq:Page, nt:base, mix:created]

Evaluating plan with index definition Lucene Index : /oak:index/ntBaseLucene

Evaluating plan with index definition Lucene Index : /oak:index/lucene-spellcheck

Applicable IndexingRule found IndexRule: nt:base

Evaluating plan with index definition Lucene Index : /oak:index/lucene

Applicable IndexingRule found IndexRule: nt:base

Evaluating plan with index definition Lucene Index : /oak:index/commerceLucene

No applicable IndexingRule found for any of the superTypes [nt:hierarchyNode, cq:Page, nt:base, mix:created]

Evaluating plan with index definition Lucene Index : /oak:index/cqProjectLucene

No applicable IndexingRule found for any of the superTypes [nt:hierarchyNode, cq:Page, nt:base, mix:created]

Evaluating plan with index definition Lucene Index : /oak:index/cqMobileAppLucene

No applicable IndexingRule found for any of the superTypes [nt:hierarchyNode, cq:Page, nt:base, mix:created]

Evaluating plan with index definition Lucene Index : /oak:index/damAssetLucene

No applicable IndexingRule found for any of the superTypes [nt:hierarchyNode, cq:Page, nt:base, mix:created]

Evaluating plan with index definition Lucene Index : /oak:index/cqPageLucene

Applicable IndexingRule found IndexRule: cq:Page

cost for lucene-property[/oak:index/cqPageLucene] is 8608.0

Full-text index without plan: "career" "contentfragment"

cost for aggregate lucene is Infinity

looking for plans for paths : []

cost for solr is Infinity

cost for traverse is Infinity

No alternatives found. Query: select [a].[jcr:path] as [jcr:path], [a].[jcr:score] as [jcr:score], [a].[jcr:primaryType] as [jcr:primaryType], [a].[jcr:createdBy] as [jcr:createdBy], [a].[jcr:created] as [jcr:created] from [cq:Page] as [a] where (contains([a].[*], 'career')) and (contains([a].[*], 'contentfragment')) and (isdescendantnode([a], [/content/we-retail/us]))

Avatar

Level 2

Sure. But I am not sure how to upload a package here.

Could you please let me know how to upload the package.

Avatar

Employee

Use advanced editor when composing a reply:

1837195_pastedImage_0.png

And use Attach option:

1837196_pastedImage_0.png

Avatar

Level 2

I don't see the "Attach" option to upload the package even in the advanced editor. Is there any other option to share the package?

Screen Shot 2019-09-24 at 3.09.56 PM.png

Avatar

Employee

you can probably use Google Drive or any other cloud resource and share a link

Avatar

Level 2

berliant​ Just shared the files through Adobe SharePoint. Please let me know if you have not received it.

Avatar

Employee

Assuming that we have a custom index that supports CF model's property, we need a union query similar to:

path=/content

1_group.1_type=nt:unstructured

1_group.1_property=name

1_group.1_property.value=Jason Chester

group.p.and

group.2_type= cq:Page

group.2_fulltext=contentfragment

Unfortunately, here it reaches a limitation of AEM 6.3 oak engine for union queries support.

If a search of CF with Multiple Elements is a firm business requirement, you can explicitly add all required element:

1837206_pastedImage_7.png

with that configuration you can use the query, that I suggested earlier:

path=/content/we-retail/us

type= cq:Page

group.p.and

group.1_fulltext=winter

group.2_fulltext=contentfragment

Avatar

Level 2

berliant Thank you!

I tried adding all the required elements within CF as recommended. But it did not resolve the search issue even with the custom index.

Screen Shot 2019-09-25 at 11.14.07 AM.png

The business requirement is to implement search capability for multiple elements of structured content fragments included on a page. We are trying to replace existing components with core content fragment components to enable content reuse across different projects/channels. But after implementing the change in a test environment, the search does not seem to work and no longer returning appropriate search results as the CF data is not available on the page.

The search does not seem to work with the Core Content Fragment component as it does not automatically add the "text" property containing selected Structured Content Fragment elements data to the component node unlike the OOB Content Fragment Component which adds the "text" property. Search works appropriately with the OOB Content Fragment Component as the CF data is available within Page structure under respective component.

Find below the "Core Content Fragment Component" node data for a test page without the "text" property.

Screen Shot 2019-09-25 at 10.59.17 AM.png

Find below the "OOB Content Fragment Component" node data containing "text" property for the same test page.

Screen Shot 2019-09-25 at 10.59.52 AM.png

Could you please let me know how the automatic addition of "text" property works for OOB component and if the same capability may be activated for the Core component to enable search functionality.

Avatar

Employee

I used your package for the test.

1. I modified the Test Page by editing the CF component. My changes implied adding two components:

1837418_pastedImage_1.png

2. It means that now the node structure includes two additional properties: elementNames and text:

1837419_pastedImage_2.png

3. Now we can use full-text search capabilities and jcr:contains function:

path=/content/we-retail/us

type= cq:Page

group.p.and

group.1_fulltext=Jason

group.2_fulltext=contentfragment

1837420_pastedImage_8.png

Note, that the query is using oak:index/cqPageLucene

For a full-text search, you don't need to edit indexes.

Make sure, that you have the same configuration and the query execution plan is also similar to what I see on my test machine. If this is not a case, it might be some bigger issue related to an oak/indexing on your AEM.

At that point, I suggest opening a support case and have a screen session with a support engineer.

Avatar

Level 2

@berliant @nagarjunav  Can you please share the fix in case you have found the root cause?

I'm facing Facing the same error & following is my analysis:
AEM version =  6.5.5

Core component version =  2.12.0

I have noticed that starting Core component 2.4.0,  when Content Fragment component was moved out of the extensions folder ( i.e. from /apps/core/wcm/extension/components/contentfragment/v1/contentfragment  TO /apps/core/wcm/components/contentfragment/v1/contentfragment), adding/editing a CF component on the page, no longer adds a "text" property to the content fragment content node & hence fulltext search does not work.

I tried the same scenario with Core Component version 2.3.2 & upon adding/editing a CF component to the page, it adds/updates the text property with values from the Content Fragment element data. Full text search works fine in this case.

Thanks,

Pravin

Avatar

Level 2

@pravinb2619228 Find below the recommended solution or workaround provided by Adobe Support for the full text search to work with content fragment component


After installing the AEM core wcm components package of version 2.4.0 or later (e.g., core.wcm.components.all-2.4.0.zip), install the AEM core wcm components extension package containing required content fragment component (e.g., core.wcm.components.extension-1.0.12.zip)

 

After installing the packages as specified, the AEM instance would contain both:
* /apps/core/wcm/extension/components/contentfragment/v1/contentfragment
* /apps/core/wcm/components/contentfragment/v1/contentfragment


Adobe support team recommended to use the contentfragment component under wcm extension directory (/apps/core/wcm/extension/components/contentfragment/v1/contentfragment) and also confirmed that the specified workaround can be used within production implementations. Also as long as you have core.wcm.components.extension-1.0.12.zip package installed, upgrading to newer core component versions in the future should not impact the contentfragment functionality, as long as the wcm core component package(s) (core.wcm.components.all-*.zip & core.wcm.components.examples-*.zip) are compatible with your AEM instance.


Please feel free to reach out to me if you have any additional questions.

 

@berliant FYI

Avatar

Level 2

Thanks @nagarjunav!! Really appreciate your response
I installed the core.wcm.components.extension-1.0.12.zip on my local (in addition to Core component 2.12.0) & full-text search works!.
I see that it now adds a "text" property to the CF content node. Were you able to figure out how this text property is added ?

I'd rather add the fix than use the CF component from extensions package because we have overlaid/extended the core CF component  & updated contentfragment.html as per project requirements.

FYI These files are not the same:
/apps/core/wcm/extension/components/contentfragment/v1/contentfragment/contentfragment.html

/apps/core/wcm/components/contentfragment/v1/contentfragment/contentfragment.html