January 1, 2021
Estimated Post Reading Time ~

Property Index in AEM 2

This post illustrates the usage of supporting properties that are part of the Oak Property Index with the sample use case.

Use case:
DAM assets have a property called "cq:parentPath" (jcr:content node of type - dam:AssetContent has this property which has the value to be its parent folder path)
Example : /content/dam/we-retail/en/features/cart.png/jcr:content


We will write a query to get all assets from we-retail/en locale which has cq:parentPath property
path=/content/dam/we-retail/en
type=dam:AssetContent
1_property=cq:parentPath
1_property.operation=exists
p.limit=-1

Create Property Index for "cq:parentPath" with mandatory properties alone.

With this setup, this index will be picked for all queries involving this property constraint + any "path" predicate.
Now to make this index to be used/picked for only certain paths we can control using includedPaths and/or excludedPaths

includedPaths:
Add below property in newly created index node - /oak:index/cqParentPath
Name                                         Type                                     Value
includedPaths                             String[]             /content/dam/we-retail/en

Index will be picked if we use the path predicate to be - /content/dam/we-retail/en or anything under /content/dam/we-retail/en/*
Index will not be picked if we use any path other than - /content/dam/we-retail/en
Example : /content/dam/we-retail or any other path altogether.

excludedPaths:
Add below property in newly created index node - /oak:index/cqParentPath
Name                                      Type                                     Value
excludedPaths                         String[]            /content/dam/we-retail/en/products

Index will not be picked if we use the path predicate to be - /content/dam/we-retail/en/products
Index will be picked if we use the path other than the content hierarchy that is part of excludedPaths.
Example:
Below paths will let the index gets picked
  • /content/dam/we-retail/en/.* or any other project dam path- /content/dam/learnings
But not the below (all 3 are part of excludedPaths)
  • /content/dam
  • /content/dam/we-retail
  • /content/dam/we-retail/en
Both together:
If below two properties are available in newly created index node - /oak:index/cqParentPath
Name                                         Type                                         Value
excludedPaths                         String[]         /content/dam/we-retail/en/products
includedPaths                          String[]         /content/dam/we-retail/en

Index will get picked for all paths under /content/dam/we-retail/en/.* except products.
Not for the below (all 3 are part of excludedPaths)
  • /content/dam
  • /content/dam/we-retail
  • /content/dam/we-retail/en (Though this is available in includedPaths, when used together with excludedPaths like above where this hierarchy is a part -> index will not be selected)
valuePattern:
Use case : Get all assets which has cq:parentPath value to be - /content/dam/we-retail/en/stores
path=/content/dam/we-retail
type=dam:AssetContent
1_property=cq:parentPath
1_property.value=/content/dam/we-retail/en/stores
p.limit=-1


Observing the value of cq:parentPath, regex pattern can be framed as
all lower case alphabets + contains "/" + can have hyphen(-) which is [a-z/\\-]+
Name                                         Type                                  Value
valuePattern                               String                             [a-b/\\-]+

valueExcludedPrefixes and valueIncludedPrefixes:
Use case :

In we-retail content, we have pages with jcr:title - "Experience" for Language master, CA and US locale (3 result set)
We will use the prefix "Exp" from this value for illustrating valueExcludedPrefixes and valueIncludedPrefixes

Query to get all pages with jcr:title - Experience
path=/content/we-retail
type=cq:Page
1_property=@jcr:content/jcr:title
1_property.value=Experience
p.limit=-1


Create Property Index for "jcr:title" with mandatory properties alone.


valueIncludedPrefixes:
Add below property in newly created index node - /oak:index/jcrTitle
Name                                     Type                                     Value
valueIncludedPrefixes             String[]                                     Exp

The index will be picked if the "property.value" predicate starts with "Exp"
The index will not be picked if the "property.value" predicate starts with anything other than "Exp"
valueExcludedPrefixes:
Add below property in newly created index node - /oak:index/jcrTitle

Name                                     Type                                     Value
valueExcludedPrefixes             String[]                                 Exp

The index will be picked if the "property.value" predicate starts with anything other than "Exp"
The index will not be picked if the "property.value" predicate starts with "Exp"

declaringNodeTypes and unique:
Usage is available OOB in below Property Index definitions.

  • /oak:index/principalName
  • /oak:index/authorizableId
For illustrating the purpose and easy follow along, have considered using existing properties as part of sample content - we.retail (for framing queries)
Play around in your local instance with your custom use case.
In real-time projects, choice of index type/mode and hence its supporting properties to be carefully arrived at considering the query predicates used for a specific functionality + content volume in a long run.


By aem4beginner

No comments:

Post a Comment

If you have any doubts or questions, please let us know.