Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

creating oak index for tagmanager aem6,5

Avatar

Level 8

Hi,

I have the below tagmanger getting results for a component.

 

Is it possible to create oak index for the below??

code:-

import com.day.cq.tagging.*;

final TagManager tagManager = getResource().getResourceResolver().adaptTo(TagManager.class);

final List<String[]> allTags = Arrays.asList(dcTags, abcTags);
Iterator<Resource> results = tagManager.find(serachPath, allTags)

 

oak index generate url:-

https://oakutils.appspot.com/generate/index

 

Regards,

Srinivas

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @srinivas_chann1,

TagManager.find method will generate XPath query like below - it can be a bit different depending on basePath and list of tags. In this example following input has been used:

  • basePath = /content
  • tagIDs = we-retail:activity/hiking, we-retail:activity/biking
/jcr:root/content//element(*, cq:Taggable)[ (@cq:tags = 'we-retail:activity/hiking' or @cq:tags = '/content/cq:tags/we-retail/activity/hiking')  and  (@cq:tags = 'we-retail:activity/biking' or @cq:tags = '/content/cq:tags/we-retail/activity/biking') ] order by @jcr:score descending

 You can see XPath query in the logs. To do this add additional logger on DEBUG level that will log com.day.cq.tagging.impl

Checking above query using AEM build in Query Performance tool, it can be seen that ntBaseLucene(/oak:index/ntBaseLucene) is used.

query.png

I think before you will decide to create custom index I would suggest to do some performance test to check if currently used will not be enough.

Knowing how the query looks and answering your question. Yes it is possible to generate index for query used by find method from TagManager, below is an example. However please remember to use custom index only if OOTB is not fully covering your use case.

<?xml version="1.0" encoding="UTF-8"?><jcr:root xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:cq="http://www.day.com/jcr/cq/1.0">
  <myIndex compatVersion="{Long}2" async="async" jcr:primaryType="oak:QueryIndexDefinition" evaluatePathRestrictions="{Boolean}true" type="lucene">
    <indexRules jcr:primaryType="nt:unstructured">
      <cq:Taggable jcr:primaryType="nt:unstructured">
        <properties jcr:primaryType="nt:unstructured">
          <tags name="cq:tags" propertyIndex="{Boolean}true" jcr:primaryType="nt:unstructured"/>
        </properties>
      </cq:Taggable>
    </indexRules>
  </myIndex>
</jcr:root>

 

View solution in original post

1 Reply

Avatar

Correct answer by
Community Advisor

Hi @srinivas_chann1,

TagManager.find method will generate XPath query like below - it can be a bit different depending on basePath and list of tags. In this example following input has been used:

  • basePath = /content
  • tagIDs = we-retail:activity/hiking, we-retail:activity/biking
/jcr:root/content//element(*, cq:Taggable)[ (@cq:tags = 'we-retail:activity/hiking' or @cq:tags = '/content/cq:tags/we-retail/activity/hiking')  and  (@cq:tags = 'we-retail:activity/biking' or @cq:tags = '/content/cq:tags/we-retail/activity/biking') ] order by @jcr:score descending

 You can see XPath query in the logs. To do this add additional logger on DEBUG level that will log com.day.cq.tagging.impl

Checking above query using AEM build in Query Performance tool, it can be seen that ntBaseLucene(/oak:index/ntBaseLucene) is used.

query.png

I think before you will decide to create custom index I would suggest to do some performance test to check if currently used will not be enough.

Knowing how the query looks and answering your question. Yes it is possible to generate index for query used by find method from TagManager, below is an example. However please remember to use custom index only if OOTB is not fully covering your use case.

<?xml version="1.0" encoding="UTF-8"?><jcr:root xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:cq="http://www.day.com/jcr/cq/1.0">
  <myIndex compatVersion="{Long}2" async="async" jcr:primaryType="oak:QueryIndexDefinition" evaluatePathRestrictions="{Boolean}true" type="lucene">
    <indexRules jcr:primaryType="nt:unstructured">
      <cq:Taggable jcr:primaryType="nt:unstructured">
        <properties jcr:primaryType="nt:unstructured">
          <tags name="cq:tags" propertyIndex="{Boolean}true" jcr:primaryType="nt:unstructured"/>
        </properties>
      </cq:Taggable>
    </indexRules>
  </myIndex>
</jcr:root>